Reputation: 3
I am trying to get all running applications, I found this on stackoverflow
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();
for (int i = 0; i < runningAppProcessInfo.size(); i++) {
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage(runningAppProcessInfo.get(i).processName);
dlgAlert.setTitle("App Title");
dlgAlert.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
but it only shows me my application (the one I am running) which is not what I want, how can I get all running applications?
Upvotes: 0
Views: 743
Reputation: 2393
This looks a lot like Android 5.1.1 and above - getRunningAppProcesses() returns my application package only
...Android 5.1.1... killed getRunningAppProcesses()... It now returns a list of your own application package.
Looks like they nerfed the method you're relying on in the exact way you're seeing. I think you might have to find a different way to do what you're doing if you can, but doubt this one will work on modern versions. It also seems like a lot of threads talk about the app/play stores writing policies that bar apps from being approved that take advantage of these permissions, so if you plan to publish your app (for whatever solution you come up with), don't forget to check into that angle too.
Upvotes: 1