我想通过杀死另一个ActivityManager.RunningServiceInfo应用程序的服务器在第三APP。 例如,一些应用程序的服务,我想保持活跃,其他服务(不适合服务START_STICK)就会被杀死。 这里是我的代码:
ActivityManager actManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
List killapplist = actManager.getRunningAppProcesses();
List killservicelist = actManager.getRunningServices(100);
for (Object aKillapplist : killapplist) {
ActivityManager.RunningAppProcessInfo localRunningAppProcessInfo = (ActivityManager.RunningAppProcessInfo)
aKillapplist;
String appname = localRunningAppProcessInfo.processName;
if (localRunningAppProcessInfo.pkgList != null) {
for (Object aKillservicelist : killservicelist) {
ActivityManager.RunningServiceInfo localRunningServiceInfo = (ActivityManager.RunningServiceInfo) aKillservicelist;
//some condition start
try {
Intent intentstop = new Intent();
intentstop.setComponent(localRunningServiceInfo.service);
mContext.stopService(intentstop);
} catch (SecurityException e) {
e.printStackTrace();
}
//some condition end
}
}
}
} else {
throw new MyException("kill list is empty");
}
然后总是提醒味精
WARN/ActivityManager(363): Permission Denial: Accessing service ComponentInfo
WARN/System.err(5992): java.lang.SecurityException: Not allowed to stop service Intent
是SYS签名的问题? 我使用了一些权限
uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"
uses-permission android:name="android.permission.SHUTDOWN"
uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"
如何解决呢? 谢谢