Android M: Programmatically revoke permissions

2020-02-10 11:56发布

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.

4条回答
家丑人穷心不美
2楼-- · 2020-02-10 11:58

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>
查看更多
成全新的幸福
3楼-- · 2020-02-10 12:19

for some special permission like SYSTEM_ALERT_WINDOW. you need this :

adb shell appops set <package_name> SYSTEM_ALERT_WINDOW allow
查看更多
啃猪蹄的小仙女
4楼-- · 2020-02-10 12:20

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.

查看更多
地球回转人心会变
5楼-- · 2020-02-10 12:22

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

But Manually you can do as given. revoke permissions manually

查看更多
登录 后发表回答