android.permission.REMOVE_TASKS:权限被拒绝 [英] android.permission.REMOVE_TASKS : Permission denied

查看:959
本文介绍了android.permission.REMOVE_TASKS:权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要删除最近的任务列表.通过谷歌搜索,我发现了来自stackoverflow的一些链接.但是他们都没有得到适当的回答.仅有一个链接

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.permission.REMOVE_TASKS被拒绝了.给出了以下代码,您可以在try-catch子句中看到该代码,因为权限被拒绝,所以代码移到catch()子句.

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; 私有方法mRemoveTask;

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);
    }
}

}`

请注意,我已经使用了这三个权限android.permission.GET_TASKS,android.permission.REORDER_TASKS,android.permission.REMOVE_TASKS 一些消息来源说要杀死后台进程,但这不会删除最近的应用程序列表. 所以我需要一些建议.

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.

推荐答案

android.permission.REMOVE_TASKS被拒绝

android.permission.REMOVE_TASKS is denied

该权限是signature级别的权限.如果您的应用使用与设备固件相同的签名密钥签名,则您将只能使用它.

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.

这篇关于android.permission.REMOVE_TASKS:权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆