判断是否在后台运行
isActivityRunningBg(String)
private boolean isActivityRunningBg(String packagename){
ActivityManager mActivityManager = (ActivityManager) getSystemService("activity");
List<RunningTaskInfo> rti = mActivityManager.getRunningTasks(20);
int rtiSize = rti.size();
int i;
for (i=0; i<rtiSize; i++) {
Log.i(TAG, "isActivityRunningBg ="+rti.get(i).baseActivity.getPackageName());
if(rti.get(i).baseActivity.getPackageName().contains(packagename)) {
Log.e(TAG,"onCreatNaviDialog apprunbg2222");
mActivityManager.moveTaskToFront(rti.get(i).id, 0,null);
return true;
}
}
return false;
}
打印日志发现,isActivityRunningBg没有生效,只获取到应用本身和Launcher
权限不够
解决
提升应用权限至system
1.Android.mk
LOCAL_CERTIFICATE := platform
2.AndroidManifest.xml
android:sharedUserId="android.uid.system"