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

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

问题描述

我可以在我的应用程序中使用 checkPermission (String permName, String 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.

可以PackageManager 上使用 checkPermission() 来查看特定应用程序(由其应用程序 ID 标识,也称为包名)拥有特定的权限.该方法返回 PERMISSION_GRANTEDPERMISSION_DENIED.

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+ 设备上,如果您正在检查的应用程序是使用 22 或更低的 targetSdkVersion 编译的,checkPermission() 将返回 PERMISSION_GRANTED 只要在清单中请求了权限(至少对于 normaldangerous 权限,这通常是您所关心的).虽然用户可以通过设置应用程序从这些应用程序撤消权限",但 checkPermission() 不会报告该状态,而且我确实不知道用户是否从某个应用程序撤消了权限应用这种方式.您可能会在一些在 Android 6.0 之前添加此类权限控制机制的自定义 ROM 上看到类似行为.

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天全站免登陆