0
我想在第三個應用中通過ActivityManager.RunningServiceInfo殺死另一個應用的服務器。 例如,我想要保存某些應用程序的服務,否則服務(不適合服務START_STICK)將被終止。 這裏是我的代碼:java.lang.SecurityException:不允許停止服務意圖?
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"
如何解決? 謝謝
在您的應用程序的Android.mk文件中,您需要添加LOCAL_CERTIFICATE:= platform – Yury
我真的忘記了這一點,非常感謝 –