在 Android 中以编程方式撤销权限 [英] Revoking permissions programmatic-ally in Android

查看:41
本文介绍了在 Android 中以编程方式撤销权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 Android Marshmallow 中的应用程序中删除或撤销权限?请注意,它应该在运行时完成,因此使用 ADB shell 脚本或将应用程序转换为它的字节 DEX 代码是没有问题的,因为架构更改不是所需解决方案的选项.

Is it possible to remove or revoke permission from an application in Android Marshmallow? Note that it should be done on runtime, so using ADB shell scripts or converting app to it's byte DEX code is out of question, as architectural changes is not an option for the required solution.

推荐答案

仅当您的应用程序是系统应用程序,并使用平台密钥进行签名时,答案是肯定的.

Only if your application is a system app, signed with the platform key then the answer is yes.

您可以通过以下方式撤销和应用权限:

You can revoke and apps permission with:

getPackageManager().revokeRuntimePermission("com.example.application", permissionName, Process.myUserHandle());

参考这里的来源:PackageManager.revokeRuntimePermissions

当您使用 Android SDK 而不是 AOSP 源构建应用时,它可能无法访问,使用反射可能会有所帮助.

It may not be accessible when you are building your app with Android SDK rather than AOSP source, use of reflection might help.

这篇关于在 Android 中以编程方式撤销权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆