Android M: programmatically revoke permissions

I am currently playing with the new Android permission system. I plan to add a screen to my settings in the application, where the user can grant or revoke permissions.

The screen will look like a normal system settings screen, but it will contain additional information why my application requires a certain resolution. This settings screen will complement the usual permission processing as suggested in the Documentation .

The working process:

  • Granting permission: open the systems dialog for granting / revoking ( as suggested here )
  • revocation resolution: revoke it programmatically

So my question is, can permissions be revoked programmatically? I searched a lot, but could not get some results.

+21
source share
4 answers

You can't do anything (at least so far). In addition, there is no intention to open the activity system settings for your application. My suggestion is to open the โ€œfeature requestโ€ on the probe tracker to preview the developer.

+11
source

You can revoke permission from the ADB command line. if you decide to write a shell script and do it all programmatically, then YES, otherwise NO

Permits for Issuance and Cancellation

You can use the new ADB package manager (pm) commands to grant and revoke permissions to the installed application. This feature may be useful for automated testing.

To grant permission, use the grant manager command of the package manager:

$ adb shell pm grant <package_name> <permission_name> 

For example, to grant permission to the com.example.myapp package to record sound, use the following command:

  $ adb shell pm grant com.example.myapp android.permission.RECORD_AUDIO 

To revoke permission, use the package manager revocation command:

  $ adb shell pm revoke <package_name> <permission_name> 
+9
source

Not. Programmatically, this is not possible in Android M Preview with new permissions.

But in manual mode, you can do what has been given. revoke permissions manually

+1
source

for some special permissions, such as SYSTEM_ALERT_WINDOW. you need this:

 adb shell appops set <package_name> SYSTEM_ALERT_WINDOW allow 
0
source

All Articles