详解Android检测权限的三种写法-创新互联
本文介绍了详解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; }
网页题目:详解Android检测权限的三种写法-创新互联
本文来源:http://lswzjz.com/article/coiiie.html