How to use android6.0, 7. 0 privilege Manager PermissionsCheckerUtil
This article mainly shows you the "android6.0, 7.0 access Manager PermissionsCheckerUtil how to use", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "android6.0, 7.0permission Manager PermissionsCheckerUtil how to use" this article.
A good android6.0, 7. 0 privilege manager PermissionsCheckerUtil
Initialize permissions Manager: constructor
Private final Context mContext;public PermissionsCheckerUtil (Context mContext) {this.mContext = mContext;}
Determine whether the permission set used has been fully allowed
/ / determine permission set public boolean lacksPermissions (String... Permissions) {for (String permission: permissions) {if (lacksPermission (permission)) {return true;}} return false;}
The core method of judging whether there is a lack of permissions
/ / determine whether the permission private boolean lacksPermission (String permission) {return ContextCompat.checkSelfPermission (mContext, permission) = = PackageManager.PERMISSION_DENIED;} is missing.
Use:
/ / add the permissions you need into the collection private static final String [] PERMISSIONS = new String [] {Manifest.permission.BLUETOOTH,Manifest.permission.BLUETOOTH_ADMIN,Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION}; public Context mContext;public static final int PERMISSION_REQUEST_CODE = 10001bot private PermissionsCheckerUtil mPermissionsCheckerUtil; / / permission detector
Initialize the permissions manager in oncreate
MContext = getApplicationContext (); mPermissionsCheckerUtil = new PermissionsCheckerUtil (mContext); initPermission ()
Initialization judgment method initPermission
Private void initPermission () {if (mPermissionsCheckerUtil.lacksPermissions (PERMISSIONS)) {ActivityCompat.requestPermissions (this, PERMISSIONS, PERMISSION_REQUEST_CODE);}} these are all the contents of this article entitled "how to use android6.0, 7. 0 permission Manager PermissionsCheckerUtil". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!