What functions or codes require GET_TASKS permission in Android?-ThrowExceptions

Exception or error:

I think the GET_TASKS permission is an orphan line in my AndroidManifest.xml. I want to remove it safely. Do you know any function or code that requires this permission? Thank you.

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

From the android reference

Allows an application to get information about the currently or
recently running tasks.

An example is public List<ActivityManager.RecentTaskInfo> getRecentTasks (int maxNum, int flags) as it throws SecurityException if the caller does not hold the GET_TASKS permission.

Note that according to the documentation

This constant was deprecated in API level 21. No longer enforced.


As of LOLLIPOP, this method is no longer available to third party
applications: the introduction of document-centric recents means it
can leak personal information to the caller. For backwards
compatibility, it will still return a small subset of its data: at
least the caller’s own tasks (though see getAppTasks() for the correct
supported way to retrieve that information), and possibly some other
tasks such as home that are known to not be sensitive.


class CheckRunningActivity extends Thread{
ActivityManager am = null;
Context context = null;

public CheckRunningActivity(Context con){
    context = con;
    am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

public void run(){

        // Return a list of the tasks that are currently running,
        // with the most recent being first and older ones after in order.
        // Taken 1 inside getRunningTasks method means want to take only
        // top activity from stack and forgot the olders.
        List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);

        String currentRunningActivityName = taskInfo.get(0).topActivity.getClassName();

        if (currentRunningActivityName.equals("PACKAGE_NAME.ACTIVITY_NAME")) {
            // show your activity here on top of PACKAGE_NAME.ACTIVITY_NAME

Leave a Reply

Your email address will not be published. Required fields are marked *