Android 獲取後臺正在執行的第三方應用列表
阿新 • • 發佈:2021-12-20
ActivityManager的getRunningServices方法和getRunningAppProcesses 方法,第三方應用都無法使用了
Android 獲取後臺正在執行的第三方應用列表(使用者安裝的應用)
環境:Android R 11 測試可行
public void getRunning3rdApp() { PackageManager localPackageManager = getPackageManager(); List localList = localPackageManager.getInstalledPackages(0); for (int i = 0; i < localList.size(); i++) { PackageInfo localPackageInfo1 = (PackageInfo) localList.get(i); String str1 = localPackageInfo1.packageName.split(":")[0]; if (((ApplicationInfo.FLAG_SYSTEM & localPackageInfo1.applicationInfo.flags) == 0) && ((ApplicationInfo.FLAG_UPDATED_SYSTEM_APP & localPackageInfo1.applicationInfo.flags) == 0) && ((ApplicationInfo.FLAG_STOPPED & localPackageInfo1.applicationInfo.flags) == 0)) {Log.d(TAG, "packageName =====>:" + str1); Intent intent = new Intent(); intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); intent.setData(Uri.parse("package:" + str1)); startActivity(intent); } } }