Android 运行时权限

添加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以上的手机上就会弹出运行时权限对话框了.

另附:

AnnotationRequiredDescription
@RuntimePermissionsRegister an Activity or Fragment to handle permissions
@NeedsPermissionAnnotate a method which performs the action that requires one or more permissions
@OnShowRationaleAnnotate 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
@OnPermissionDeniedAnnotate a method which is invoked if the user doesn’t grant the permissions
@OnNeverAskAgainAnnotate a method which is invoked if the user chose to have the device “never ask again” about a permission
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值