I'm designing an application for removing recents tasks. Because of the need to access system permissions like REMOVE_TASKS
and i got this in my log
Caused by: java.lang.SecurityException: Permission Denial: removeTask() from pid=12579, uid=10066 requires android.permission.REMOVE_TASKS
I am using this code:
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<ActivityManager.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);
}
}