简体   繁体   中英

Android Java Get All Running Apps Even If They Are Running In Background

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM