In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to achieve permission request in Android". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Android M (6. 0) API 23 added permission request settings, APP needs to use some permissions need to apply actively.
Permissions are divided into three categories, one group is Normal permission, there is no need to apply, the other group is Dangerous, need to apply, and then special permissions, need to apply.
First, take a look at the Normal permission list:
Let's take a look at the Dangerous permission list:
In fact, dangerous permissions are the main objects that runtime permissions deal with, and these permissions may cause privacy issues or affect the operation of other programs. Dangerous permissions in Android can be grouped into the following groups:
CALENDAR
CAMERA
CONTACTS
LOCATION
MICROPHONE
PHONE
SENSORS
SMS
STORAGE
For each permission group and its specific permissions, please refer to the following figure:
It's easy not to support the runtime permission mechanism, just set the targetSdkVersion below 23, which means to tell the system that I'm not completely done on API 23, and don't start any new features for me.
Special permissions:
That is, some particularly sensitive permissions, in the Android system, are mainly composed of two
SYSTEM_ALERT_WINDOW, set up suspension windows, do some cool techs.
WRITE_SETTINGS modifies system settings
With regard to the authorization of the above two special permissions, it is done by using the startActivityForResult startup authorization interface.
Request SYSTEM_ALERT_WINDOW
Private static final int REQUEST_CODE = 1 private void requestAlertWindowPermission () {Intent intent = new Intent (Settings.ACTION_MANAGE_OVERLAY_PERMISSION); intent.setData (Uri.parse ("package:" + getPackageName ()); startActivityForResult (intent, REQUEST_CODE);} @ Overrideprotected void onActivityResult (int requestCode, int resultCode, Intent data) {super.onActivityResult (requestCode, resultCode, data); if (requestCode = = REQUEST_CODE) {if (Settings.canDrawOverlays (this)) {Log.i (LOGTAG, "onActivityResult granted");}
What you need to note in the above code is that
Start implicit Intent using Action Settings.ACTION_MANAGE_OVERLAY_PERMISSION
Use "package:" + getPackageName () to carry the package name information of App
Using Settings.canDrawOverlays method to judge the result of authorization
Request WRITE_SETTINGS
Private static final int REQUEST_CODE_WRITE_SETTINGS = 2private void requestWriteSettings () {Intent intent = new Intent (Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData (Uri.parse ("package:" + getPackageName ()); startActivityForResult (intent, REQUEST_CODE_WRITE_SETTINGS);} @ Overrideprotected void onActivityResult (int requestCode, int resultCode, Intent data) {super.onActivityResult (requestCode, resultCode, data) If (requestCode = = REQUEST_CODE_WRITE_SETTINGS) {if (Settings.System.canWrite (this)) {Log.i (LOGTAG, "onActivityResult write settings granted");}
What you need to note in the above code is that
Start implicit Intent using Action Settings.ACTION_MANAGE_WRITE_SETTINGS
Use "package:" + getPackageName () to carry the package name information of App
Using Settings.System.canWrite method to detect the result of authorization
Note: with regard to these two special permissions, it is generally not recommended to apply.
In fact, you don't need to apply for every permission explicitly. For example, if your app authorizes access to read contacts, then your app is also given permission to write contacts. Because both the read and write contact permissions belong to the contact permission group, once a permission in the group is allowed, other permissions in the group are also allowed.
This is the end of the content of "how to implement permission request in Android". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.