添加dependencies

build.gradle(Project)中添加

    buildscript {        dependencies {            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'        }    }

build.gradle(Module)中添加

    apply plugin: 'android-apt'    targetSdkVersion 23    dependencies {        compile 'com.github.hotchemi:permissionsdispatcher:2.1.3'        apt 'com.github.hotchemi:permissionsdispatcher-processor:2.1.3'    }

结合PermissionsDispatcher plugin插件就可以Generate需要的代码了

PermissionsDispatcher plugin

  • 右键 Generate
  • Generate Runtime Permission…

  • Method name 里面填写名称点击Generate
  • 弹出Rebuild对话框, 点允许

这样在Android 6.0以上的手机上就会弹出运行时权限对话框了.

另附:

Annotation Required Description
@RuntimePermissions Register an Activity or Fragment to handle permissions
@NeedsPermission Annotate a method which performs the action that requires one or more permissions
@OnShowRationale Annotate a method which explains why the permission/s is/are needed. It passes in a PermissionRequest object which can be used to continue or abort the current permission request upon user input
@OnPermissionDenied Annotate a method which is invoked if the user doesn’t grant the permissions
@OnNeverAskAgain Annotate a method which is invoked if the user chose to have the device “never ask again” about a permission

更多相关文章

  1. Android(安卓)SDK Manager无法更新的解决
  2. Android一款界面良好使用简单的弹出框
  3. Flutter Android启动源码分析(一)
  4. android sdk 更新速度慢的解决办法
  5. Android(安卓)studio so库找不到问题
  6. Android(安卓)- HTTP util class SyncGET & SyncPOST
  7. Android(安卓)添加删除联系人2.0之前与2.0之后
  8. Android(安卓)day_11 (四种对话框)
  9. 自定义对话框

随机推荐

  1. Android解析中国天气接口JSon数据,应用于
  2. [置顶] Android系统移植与调试之------->
  3. Android(安卓)ndk 开发环境搭建 和 示例
  4. Android开发5――文件读写
  5. android中Parcelable接口的使用
  6. android制作开关机动画注意事项
  7. Android初级教程理论知识(第一章快速入门)
  8. Android(安卓)关于android:foreground设
  9. Android笔试总结
  10. Android(安卓)开机图片/文字/动画 修改