Android的危险权限列表,因此开发中为了适应6.0系统,我们需要进行再执行代码时需要对应权限之前,去向用户请求我们需要操作的对应权限。 项目的GitHub地址:https://github.com/hotchemi/PermissionsDispatcher
For Android Gradle Plugin >= 2.2 users (Android Studio2.2以上包含2.2的用户这样配置)
To add it to your project, include the following in your app module build.gradle file:
${latest.version} is Download (2017年3月9日18:13:31 的最新版为:2.3.1)
dependencies { compile 'com.github.hotchemi:permissionsdispatcher:${latest.version}' annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:${latest.version}' }For Android Gradle Plugin < 2.2 users(Android Studio2.2以下上的用户这样配置)
To add it to your project, include the following in your project build.gradle file:
buildscript { dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } }Snapshots of the development version are available in JFrog’s snapshots repository. Add the repo below to download SNAPSHOT releases.
repositories { jcenter() maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' } }And on your app module build.gradle:
${latest.version} is Download
apply plugin: 'android-apt' dependencies { compile 'com.github.hotchemi:permissionsdispatcher:${latest.version}' apt 'com.github.hotchemi:permissionsdispatcher-processor:${latest.version}' }使用步骤
步骤几步骤名称功能第一步@RuntimePermissions需要在Activity的Class声明此注解,来处理我们的权限第二步@NeedsPermission注释请求的权限后面跟着权限获取后执行的方法第三步@OnShowRationale一般用于展示用户点击取消后向用户说明原因,在positiveButton上一般帮一个监听器执行request.proceed()方法,在取消按钮上帮一个监听器执行request.cancel()方法第四步@OnPermissionDenied用户拒绝后执行的方法第五步@OnNeverAskAgain用户点击不再询问后执行的方法第六步MainActivityPermissionsDispatcher.showXXXXWithCheck(MainActivity.this);此方法用于在适当时候获取权限,具体内容可以在生成的辅助类MainActivityPermissionsDispatcher中间查看第七部调用辅助类处理放回的结果