/**
* 通过包名获取task id,不存在为-1
*
* @param packageName
* @return
*/
public int getTaskId(String packageName) {
String result = execRootCmd("dumpsys activity | grep " + packageName);
int start = result.indexOf("TaskRecord{");
if(start > 0){
int end = result.indexOf("}", start);
if(start < end){
String taskStr = result.substring(start + 1, end);
start = -1;
end = -1;
start = taskStr.indexOf("#");
if (start > 0) {
end = taskStr.indexOf(" ", start);
if (start < end) {
String idStr = taskStr.substring(start + 1, end);
Log.d(TAG, "getTaskId:" + idStr);
if (isNumeric(idStr))
return Integer.parseInt(idStr);
}
}
}
}
return -1;
}
Sharezer , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明通过adb获取task id!