Android 获取后台正在运行的第三方应用列表
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);
}
}
}