如何检查从权限授予了哪些其他应用程序 [英] How to check what other apps granted from permissions

查看:56
本文介绍了如何检查从权限授予了哪些其他应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在应用程序内部使用 checkPermission(字符串permName,字符串pkgName)来检查其他已授予权限的应用程序吗?

Can I use checkPermission (String permName, String pkgName) inside my application to check other apps granted permissions?

例如,如果我想检查是否已授予我的设备中安装的app1授予 android.permission.WRITE_CONTACTS 的权限,我可以使用 checkPermission 来检查我的应用程序中的内容还是不是 ?我知道新版的棉花糖允许用户撤消某些权限,为此我要检查

for example If I want to check if app1 which is installed in my device granted android.permission.WRITE_CONTACTS , can I use checkPermission to check that in my app or not ? I know the new release of marshmallow allow user to revoke some permissions, for that I want to check it

如果不允许这样做,请提出替代方法.此有关checkPermission的更多信息

If that is not allowed please suggest alternative method. This more information about checkPermission

推荐答案

PERMISSION_GRANTED 是一个数字.具体来说,它的值为0 .您不能使用数字来检查任何内容.

PERMISSION_GRANTED is a number. Specifically, it has a value of 0. You cannot use a number to check anything.

可以

You can use checkPermission() on PackageManager to see whether a particular app (identified by its application ID, a.k.a. package name) holds a particular permission. That method returns either PERMISSION_GRANTED or PERMISSION_DENIED.

但是,请注意,在Android 6.0+设备上,如果您要检查的应用是使用 targetSdkVersion 为22或更低版本编译的,则 checkPermission()将返回 PERMISSION_GRANTED ,只要在清单中请求了许可(至少对于 normal dangerous 许可,通常是与您有关的许可).虽然用户可以通过设置"应用从这些应用撤消权限",但 checkPermission()不会报告该状态,实际上我无法确定用户是否从某个应用撤消了权限.应用程序以这种方式.您可能会在一些自定义ROM上看到类似的行为,这些自定义ROM在Android 6.0之前添加了这种权限控制机制.

However, note that on Android 6.0+ devices, if the app you are checking is compiled with a targetSdkVersion of 22 or lower, checkPermission() will return PERMISSION_GRANTED so long as the permission was requested in the manifest (at least for normal and dangerous permissions, which are usually the ones that concern you). While the user can "revoke permissions" from those apps via the Settings app, that status is not reported by checkPermission(), and indeed I know of no way to find out whether the user revoked permissions from an app this way. You may see similar behavior on some custom ROMs that added this sort of permission control mechanism prior to Android 6.0.

这篇关于如何检查从权限授予了哪些其他应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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