0

I want to remove recent task list. Through googling I have found some links from stackoverflow. But none of them has been properly answered. Only one link

Android, how to clear the recent task list which could get from Home button in most phone? Reflection is a possible way?

has showed a way using reflection. But now, I am facing a problem, android.permission.REMOVE_TASKS is denied. The code below is given, where you can see that in the try-catch clause, as the permission is denied,the code moves to catch() clause.

enter code here

private ActivityManager mActivityManager = null; private Method mRemoveTask;

public MyActivityManager(Context context) {
    try {
         Class<?> activityManagerClass =         Class.forName("android.app.ActivityManager");
        mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

        mRemoveTask = activityManagerClass.getMethod("removeTask", new Class[] { int.class, int.class });
        mRemoveTask.setAccessible(true);

    }
    catch ( ClassNotFoundException e ) {
        Log.i("MyActivityManager", "No Such Class Found Exception", e);
    }
    catch ( Exception e ) {
        Log.i("MyActivityManager", "General Exception occurred", e);
    }
}

/**
 * If set, the process of the root activity of the task will be killed
 * as part of removing the task.
 */
public static final int REMOVE_TASK_KILL_PROCESS = 0x0001;

/**
 * Completely remove the given task.
 *
 * @param taskId Identifier of the task to be removed.
 * @param flags Additional operational flags.  May be 0 or
 * {@link #REMOVE_TASK_KILL_PROCESS}.
 * @return Returns true if the given task was found and removed.
 */
public boolean removeTask(int taskId, int flags) {
    try {
        return (Boolean) mRemoveTask.invoke(mActivityManager, Integer.valueOf(taskId), Integer.valueOf(flags) );
    } catch (Exception ex) {
        Log.i("MyActivityManager", "Task removal failed", ex);
    }
    return false;
}

public void clearRecentTasks() {
    List<RecentTaskInfo> recents = mActivityManager.getRecentTasks(1000, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
    // Start from 1, since we don't want to kill ourselves!
    for( int i=1; i < recents.size(); i++ ) {
        removeTask( recents.get(i).persistentId, 0);
    }
}

}`

Here to be noted that, I have used this three permissions android.permission.GET_TASKS, android.permission.REORDER_TASKS, android.permission.REMOVE_TASKS some sources saying to kill background processes, but that will not remove the recent apps list. So I need some suggestions.

Community
  • 1
  • 1

1 Answers1

0

android.permission.REMOVE_TASKS is denied

That permission is a signature-level permission. You will only be able to use it if your app is signed by the same signing key as the device firmware.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • then plz, kindly can you tell me, how can I solve it?? It is very necessary – Rayhanul Masud Feb 03 '15 at 01:16
  • @RayhanulMasud: If you want to hold that permission, you will need to build your own ROM mod, then sign your app with the same signing key that signed the ROM mod. Your app will only hold that permission when running on that ROM mod. – CommonsWare Feb 03 '15 at 01:27
  • sir, as i am a beginner in cse background, i have very less knowledge about os level topics. I have googled about your last suggestion given, but did not understand properly. Can you please, tell me specificly how can i solve my problem. How can i sign my app with the same signing key and hold the permission to remove task. – Rayhanul Masud Feb 05 '15 at 07:39