我可以检测到我的android应用已删除特定权限吗? [英] Can I detect that a particular permission has been removed for my android app?
问题描述
因此,随着Android 4.3的到来,可以选择性地禁用特定权限用于应用。
So with the arrival of Android 4.3 comes the ability to selectively disable particular permissions for apps.
如果应用失去了需要正确运行的权限,这显然会引起问题。
This could obviously cause problems where an app loses a permission it needs to operate correctly.
撤消权限后广播消息,或者如何得知我的应用不再具有特定权限?理想情况下,我想通知用户,关闭权限A会破坏应用程序中的xyz。
Does the system broadcast a message when a permission is revoked, or how could I tell that my app no longer has a certain permission? Ideally I would like to inform the user that turning off permission A will break xyz in the application.
推荐答案
没有广播,但是您可以自己检查启动(或恢复等)的权限。 Context#checkCallingOrSelfPermission ()
。
There is no broadcast, but you can check permissions yourself on startup(or resume, etc). Context#checkCallingOrSelfPermission()
is provided for this.
如果要检查所有权限,可以执行以下操作:
If you want to check all your permissions, you could do something like this:
public static boolean[] getPermissionsGranted(Context context, String[] permissions){
boolean[] permissionsGranted = new boolean[permissions.length];
for(int i=0;i<permissions.length;i++){
int check = context.checkCallingOrSelfPermission(permissions[i]);
permissionsGranted[i] = (check == PackageManager.PERMISSION_GRANTED);
}
return permissionsGranted;
}
其中输入字符串是权限的名称,例如 android.permission.INTERNET
。
Where the input Strings are the permissions' names, such as "android.permission.INTERNET"
.
这篇关于我可以检测到我的android应用已删除特定权限吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!