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 > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
It is believed that many inexperienced people don't know what to do about how to get permission dynamically in Android 6.0. therefore, this paper summarizes the causes and solutions of the problem. I hope you can solve this problem through this article.
Which permissions need to be applied for
At present, all permissions in Android can be divided into two types, one is ordinary permissions, the other is dangerous permissions. General permissions refer to permissions that do not directly threaten the security and privacy of users. The system will automatically apply for these permissions for us. Dangerous permissions are rights that may threaten the privacy of users and the security of devices. These permissions include obtaining contact information, obtaining the geographic location of the device, turning on the camera, and so on. This dangerous permission must be judged and managed by the user after Android 6. 0. If the user is authorized, the application will have this corresponding function.
The following figure shows a list of dangerous permissions, with a total of 9 groups of 24 permissions.
One thing to note: if a permission in the permission group is authorized by the user, then all other permissions in the permission group will be granted at the same time.
0x02 implementation
I wrote a demo myself based on the samples-23_r02\ system\ RuntimePermissions\ example code. Demo is a function that dynamically acquires camera permissions. If the user agrees to the authorization, the camera preview screen will be obtained.
1) add camera permissions to the AndroidMesifest.xml file
2) use ActivityCompat.checkPermission () to determine whether the permissions you need have been authorized by the user. The first parameter of this method is the context, and the second parameter is the specific permission name.
The code can be written as follows:
I have extracted the permissions in demo and encapsulated them in a tool.
In MainActivity, determine permissions:
In PermissionUtil, implement:
3) if you don't get the permission, you need to call the ActivityCompat.requestPermissions () method to apply for the permission and implement the onRequestPermissionsResult () method.
RequestPermissions () has a total of three parameters, the first is an instance of Activity, the second is an String array, and the second is the request code, which can be defined by yourself, as long as you make sure it is a unique value.
In demo, in order to be compatible with applying for more than one permission at a time, my own implementation code is as follows:
The concrete implementation of the onRequestPermissionsResult () method:
After reading the above, have you mastered the method of how to obtain permissions dynamically in Android 6.0? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.