Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use android6.0, 7. 0 privilege Manager PermissionsCheckerUtil

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report