/**
* 返回当前的应用是否处于前台显示状态
*
* @param packageName
* @return
*/
public boolean isTopActivity(String packageName) {
String result = execRootCmd("dumpsys activity | grep \"mResumedActivity\"");
int start = result.indexOf("u0") + 3;
int end = result.indexOf("/");
Log.d(TAG, "s: " + sta……继续阅读 »
sharezer
7年前 (2017-06-02) 2781浏览 0评论
3个赞
public boolean isNumeric(String str) {
for (int i = 0; i < str.length(); i++) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
……继续阅读 »
sharezer
7年前 (2017-06-02) 2363浏览 0评论
0个赞
这里使用的是ps命令,不用root或系统权限。
public int getPid(String name) {
String cmd = ("ps | grep " + name);
String str = execRootCmd(cmd);
if (str == null || str == "" || str.length() < 1)
return -1;
else {
String[] arr = str.split("\\s+");
……继续阅读 »
sharezer
7年前 (2017-06-02) 3337浏览 0评论
5个赞
// 执行命令并且输出结果
private String execRootCmd(String cmd) {
Log.d(TAG, "cmd: " + cmd);
String result = "";
DataOutputStream dos = null;
DataInputStream dis = null;
try {
Process p = Runtime.getRuntime().exec("su");// 经过Root处理的android系统即有su命令
……继续阅读 »
sharezer
7年前 (2017-06-02) 2478浏览 0评论
2个赞