Android 运行时权限
2016-07-14 20:31
501 查看
添加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
右键 GenerateGenerate 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 |
相关文章推荐
- 自定义圆形ImageView(仿QQ头像)
- AsyncTask官网API翻译
- Android中自定义View
- Android 的坑!
- Android Studio快捷键(Mac OS X 10.5+)
- 解决android studio过慢的问题
- Android自定义Dialog弹窗获取Dialog中的控件ID
- Animation从左边开始缩放
- 使用Android Studio导入源码
- Android Studio入门到精通
- Android逆向分析(2) APK的打包与安装
- Android Studio 对GitHub开源项目的引用及导入
- Android相机,YV12ToRGB24,rgbToBitmap
- android studio for android learning (十五) Camera2界面定制与保存到外部存储
- Android Studio 开发环境的搭建与安装
- Android中数据解析的实现
- Android开发学习笔记(二)——编译和运行原理(1)
- android sdk启动报错error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037:
- CardView
- android 蓝牙4.0 分包传输数据 问题