Neither user 10036 nor current process has android

2019-07-16 12:37发布

问题:

I need to power off device by button on my application. I add permission to manifest file:

 <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="13" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.DEVICE_POWER"/>

And use powerOff method on click button:

void powerOff(){
        PowerManager pm = (PowerManager) getSystemService(this.POWER_SERVICE);
        pm.goToSleep(SystemClock.uptimeMillis());
    }

When I click button I get error:

Neither user 10036 nor current process has android.permission.DEVICE_POWER.

回答1:

DEVICE_POWER is a restricted permission. PackageManager won't grant you this unless your app is signed with the system signature.