Question

In the AndroidManifest.xml, I have this permission:

<user-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

But still I am getting the error message as:

Permission Denial: killBackgroundProcesses() from ... requires android.permission.KILL_BACKGROUND_PROCESSES

This method was invoked from:

    ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
    for(RunningAppProcessInfo runningProcess : runningProcesses) {
        if(runningProcess.processName.equals("com.example.nihao")) {
            Log.v("Hello", "kill process "+runningProcess.pid);
            //android.os.Process.killProcess(runningProcess.pid);
            am.killBackgroundProcesses("com.example.nihao");
        }
    }

Any clue?

Was it helpful?

Solution

You have a typo, user-permission should be uses-permission.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top