MPermissions动态权限的使用步骤
1.
project's build.gradle 引入
buildscript {
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
2.module's buid.gradle
apply plugin: 'com.neenbedankt.android-apt' dependencies { apt 'com.zhy:mpermission-compiler:1.0.0' compile 'com.zhy:mpermission-api:1.0.0' }
3.在需要调用的时候使用。也可以在已进入应用的时候进行申请。
MPermissions.requestPermissions(MainActivity.this, REQUECT_CODE_SDCARD, Manifest.permission.WRITE_EXTERNAL_STORAGE);4.处理回调@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { MPermissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults); } //请求成功 @PermissionGrant(REQUECT_CODE_SDCARD) public void requestSdcardSuccess() { Toast.makeText(this, "GRANT ACCESS SDCARD!", Toast.LENGTH_SHORT).show(); } //请求失败 @PermissionDenied(REQUECT_CODE_SDCARD) public void requestSdcardFailed() { Toast.makeText(this, "DENY ACCESS SDCARD!", Toast.LENGTH_SHORT).show(); }