Android M Permissions : the usage of shouldShowRequestPermissionRationale() function
来源:互联网 发布:大数据译见 编辑:程序博客网 时间:2024/06/06 04:03
http://stackoverflow.com/questions/32347532/android-m-permissions-confused-on-the-usage-of-shouldshowrequestpermissionrati
After M Preview 1, if the dialog is displayed for the first time, there is no Never ask againcheckbox.
If the user denies the permission request, there will be a Never ask again checkbox in the permission dialog the second time permission is requested.
So the logic should be like this:
Request permission:
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);} else { //Do the stuff that requires permission...}
Check if the permission was denied or granted in
onRequestPermissionsResult
.If the permission was denied previously, this time there will be a Never ask again checkbox in the permission dialog.
Call
shouldShowRequestPermissionRationale
to see if the user checked Never ask again.shouldShowRequestPermissionRationale
method returns false only if the user selectedNever ask again or device policy prohibits the app from having that permission:if (grantResults.length > 0){ if(grantResults[0] == PackageManager.PERMISSION_GRANTED) { //Do the stuff that requires permission... }else if (grantResults[0] == PackageManager.PERMISSION_DENIED){ // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { //Show permission explanation dialog... }else{ //Never ask again selected, or device policy prohibits the app from having that permission. //So, disable that feature, or fall back to another situation... } }}
So, you won't have to track if a user checked Never ask again or not.
- Android M Permissions : the usage of shouldShowRequestPermissionRationale() function
- Android 笔记 permissions 之 shouldShowRequestPermissionRationale()
- the usage of android viewpage
- Android M App Permissions
- Android M App Permissions
- usage of c/c++ function
- The usage of finalize()
- usage of the serialVersionUID
- the usage of lucene
- The usage of SQLPATH
- the usage of sscanf()
- the usage of vim
- The usage of #pragma
- The usage of InjectView
- Android M Permissions 权限管理
- 理解 Android M 中的Permissions
- Analyzing the memory usage of your Android application
- 内存泄露 Analyzing the memory usage of your Android application
- 电文的编码和译码(哈夫曼树的应用)
- Ubuntu windows 双系统没有windows启动项
- Mysql 5.7版本报错 1055
- ubuntu下如何关闭无响应程序
- tomcat中的logging.properties配置具体分析
- Android M Permissions : the usage of shouldShowRequestPermissionRationale() function
- CEF3开发者系列之进程和线程
- mysql的排序检索顺序ORDER BY
- wamp环境下用phpstudy对hosts和httpd.conf的配置
- java 字节码校验
- Web程序运行过程中报OutOfMemoryError: Java heap space错
- threejs第五篇【一条龙测试之四 threejs 给obj模型贴图】
- 利用Nginx构建负载均衡服务器
- 技术文章收集