我想關閉Android服務中的當前前臺應用程序。但是,它不起作用。你能讓我解決它嗎?謝謝。如何關閉Android服務中的前臺應用程序?
ActivityManager manager = (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE);
List<ApplicationInfo> packages;
PackageManager pm;
pm = getPackageManager();
//get a list of installed apps.
packages = pm.getInstalledApplications(0);
ActivityManager mActivityManager = (ActivityManager)getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
String myPackage = getApplicationContext().getPackageName();
for (ApplicationInfo packageInfo : packages) {
if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1)continue;
if(packageInfo.packageName.equals(myPackage)) {
Log.d(TAG,"*************"+packageInfo.packageName);
mActivityManager.killBackgroundProcesses(packageInfo.packageName);
}
}
也去功能killBackgroundProcesses
但不會關閉我當前的前景應用程序。我在Android L系統運行許可
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
檢查這個http://stackoverflow.com/questions/6733311/android-killing-all-foreground-running-app – Tasneem