Android6. 0 imitation wechat permission settings

Android version 6.0 is the most unfriendly to programmers. The setting of dynamic permissions once bothered me. At present, most frameworks for setting 6.0 permissions basically access multiple permissions at one time. The problem is that if we apply for three permissions and the user agrees to only one of them, The next time I apply for permission, I will apply for three kinds at one time, which is very inconvenient and unfriendly to users. I found this article of Android monkey by chance, http://sunjiajia.com/2016/04/19/android-m-permissions/ On this basis, it is modified to achieve the desired effect (following the wechat access permission setting, only one permission is accessed at a time on the startup page, and the user agrees to continue to access the next permission. If the user chooses to refuse, no matter whether the user chooses "no longer ask" or "refuse" It is regarded as rejection, and a prompt box will pop up to prompt the necessity of the permission and guide the user to open the permission.) next, we take the storage space, telephone and camera permission as an example. Sorry for the poor picture~~

add permission

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CALL_PHONE" />

Permission processing tool class

Usage: when starting the page appstart to jump to the home page, call

This is the callback in appstart. The current processing method is to process the corresponding permissions according to the callback results of each proposed permission application. After each processing, it will traverse the "permissions_group_sort" and process all permissions in a circular manner until each permission is obtained and jump in "onpermissionsgranted()". In this way, the processing can directly ask for the permissions not obtained at the next startup.

If there are several permissions in the set permission group, you need to write several judgments in this callback to process the corresponding friendly prompt information, one-to-one processing. This method avoids constantly talking to the user and simply and rudely prompts the user to obtain permissions. Once the user does not follow, he will directly skip the setting and exit the application. Here is the GIT address https://git.oschina.net/feiyangwei/PermissionDemo.git At present, this scheme still needs to be improved. If the user sets the modification permission inside when opening the application, I don't know how to monitor the modification of this permission. Wechat directly reopens the application, which will regain the permission. If there is a great God who knows, you can discuss it.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>