29

I am currently playing around with android m's new permission system. What i am planning is to add a screen to my in-app settings where the user can grant or revoke permissions.

The screen would look like the regular system settings screen, but will have additional information why my app needs the specific permission. This settings screen would be an addition to the regular permission handling as suggested in the Documentation.

The workflow would be:

  • granting permission: open the systems dialog to grant/revoke (like suggested here)
  • revoking permission: revoke it programmatically

So my question is, can permissions be revoked programatically? I searched a lot, but didn't manage to get some results.

angryITguy
  • 9,332
  • 8
  • 54
  • 82
W3hri
  • 1,563
  • 2
  • 18
  • 31
  • Answer seems to be "No". See http://stackoverflow.com/questions/7517171/is-there-any-way-to-ask-permission-programmatically and http://stackoverflow.com/questions/19462511/is-it-possible-to-specify-the-uses-permission-programatically. – Mihai8 Jul 21 '15 at 09:25
  • 1
    These Q/As refer to the 'old' permissions system, where all permissions are granted upon installation. My question is relating to new new system unter Andoid M – W3hri Jul 21 '15 at 09:27

5 Answers5

15

You can't do anything (at least until now). In addition, there isn't any intent action to open the activity system settings for your app. My suggestion is to open a "feature request" on the developer preview issue tracker.

greywolf82
  • 21,813
  • 18
  • 54
  • 108
  • Thats sad, especially as opening the intent of the systemsettings was my plan b. I think i should open a feature request then. – W3hri Jul 22 '15 at 08:30
  • @greywolf82: do you know if this is still the case with the latest version of Android? – narb Sep 13 '17 at 16:52
  • @narb this has changed as of SDK 33. I posted an answer with the solution. – Oliver Metz Sep 20 '22 at 04:02
12

You can revoke permission from ADB Shell. if you consider writing shell script and doing all this under programatically then YES, else NO

Grant and revoke permissions

You can use new ADB package manager (pm) commands to grant and revoke permissions to an installed app. This functionality can be useful for automated testing.

To grant a permission, use the package manager's grant command:

$ adb shell pm grant <package_name> <permission_name>

For example, to grant the com.example.myapp package permission to record audio, use this command:

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

To revoke a permission, use the package manager's revoke command:

 $ adb shell pm revoke <package_name> <permission_name>
frogatto
  • 28,539
  • 11
  • 83
  • 129
dex
  • 5,182
  • 1
  • 23
  • 41
6

Starting API 33 (Android 13) you can programmatically revoke previously granted runtime permissions via the revokeSelfPermissionOnKill APIs. E.g.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
   context.revokeSelfPermissionOnKill(Manifest.permission.POST_NOTIFICATIONS)
}

Triggers the asynchronous revocation of a runtime permission. If the permission is not currently granted, nothing happens (even if later granted by the user).

There is also a function which takes a collection of multiple permissions to revoke.

Be sure to also put a version code guard around this as there currently doesn't seem to be a warning in the IDE. Unfortunately this hasn't been added to ContextCompat yet.

Oliver Metz
  • 2,712
  • 2
  • 20
  • 32
1

No Programmatically it is not possible in Android M Preview with new permissions Model.

But Manually you can do as given. revoke permissions manually

Sushil
  • 147
  • 1
  • 9
-1

for some special permission like SYSTEM_ALERT_WINDOW. you need this :

adb shell appops set <package_name> SYSTEM_ALERT_WINDOW allow
i love jack
  • 119
  • 3
  • 9