سؤال

I have a button in a service where the user clicks on it the recent apps dialog will appear, but I don't know a proper way to achieve that, can anyone help?

هل كانت مفيدة؟

المحلول

ActivityManager has method getrunningtasks() .

ActivityManager activity_manager = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);

then call the getRunningtasks() to get a list of the current Running tasks :

List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

for (int i = 0; i < recentTasks.size(); i++) {
            Log.d("Executed app",
                    "Application executed : "
                            + recentTasks.get(i).baseActivity.toShortString()
                            + "\t\t ID: " + recentTasks.get(i).id + "");
        }

and please add the permission to get the running tasks in your manifest file like the following :

  <uses-permission  android:name="android.permission.GET_TASKS"/>

Hope that helps .

نصائح أخرى

Recent apps can be opened using the TOGGLE_RECENTS Intent.

Intent intent = new Intent ("com.android.systemui.recent.action.TOGGLE_RECENTS");
intent.setComponent (new ComponentName ("com.android.systemui", "com.android.systemui.recent.RecentsActivity");
startActivity (intent);

You can make your own dialog to show recent apps

ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);

then you can get all running apps with

getRunningTasks
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top