0

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?

  • Do you think maybe your android app is sandboxed such that it purposefully can't directly see those other processes. Perhaps there is a context where the code you found would work (app runs as root etc.). – Atmas Apr 29 '21 at 21:40
  • @Atmas , I am running this on my phone, nothing about root was mentioned, this way was mentioned in about 5 answers for getting running background apps – DemonSlayerXS Apr 29 '21 at 21:51
  • Which version of Android? – Atmas Apr 29 '21 at 21:56
  • @Atmas 7.0, (I wrote this 20min ago and forgot to click "Add comment" somehow, sorry) – DemonSlayerXS Apr 29 '21 at 22:20

1 Answers1

1

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.

Atmas
  • 2,389
  • 5
  • 13
  • I checked the link, and it said "Google has significantly restricted access to /proc in Android Nougat. This library will **not work on Android 7.0**. Please star this issue." RIP – DemonSlayerXS Apr 30 '21 at 18:42
  • Yeah so no go then. Maybe post an update on the other thread if you find a better way. Feel free to upvote/accept if my answer helped bring you some closure! – Atmas Apr 30 '21 at 20:17
  • okay, i cannot upvote, i dont have enough reps – DemonSlayerXS May 02 '21 at 09:26