最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
详解Android 检测权限的三种写法
时间:2022-06-25 22:47:19 编辑:袖梨 来源:一聚教程网
本文介绍了详解Android 检测权限的三种写法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
权限检测生效条件:
- targetSdkVersion 以及 compileSdkVersion 升级到 23 及以上
-
运行 Android 系统 6.0 及以上
三种检测权限写法:
public static boolean checkPermission1(Context context, String[] permissions) {
PackageManager packageManager = context.getPackageManager();
String packageName = context.getPackageName();
for (String permission : permissions) {
int per = packageManager.checkPermission(permission, packageName);
if (PackageManager.PERMISSION_DENIED == per) {
Log.w(TAG, "required permission not granted . permission = " + permission);
return false;
}
}
return true;
}
public static boolean checkPermission2(Context context, String[] permissions) {
for (String permission : permissions) {
int per =context.checkPermission(permission, Process.myPid(),Process.myUid());
if (PackageManager.PERMISSION_GRANTED != per) {
Log.w(TAG, "required permission not granted . permission = " + permission);
return false;
}
}
return true;
}
public static boolean checkPermission3(Context context, String[] permissions) {
for (String permission : permissions) {
int per = ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA);
if (PackageManager.PERMISSION_GRANTED != per) {
Log.w(TAG, "required permission not granted . permission = " + permission);
return false;
}
}
return true;
}
相关文章
- 星球重启夜袭者专精选择推荐 夜袭者专精点什么 11-29
- dnf神界版本辅助职业固定史诗选择推荐 11-29
- 如龙8多少钱 steam各版本价格介绍 11-29
- 绝区零叶瞬光上线时间介绍 11-29
- 我的H暑假攻略大全 全CG/全结局/全物品获取/好感度事件指南 11-29
- dnf神界版本缪斯装备搭配毕业攻略 缪斯装备怎么选 11-29