一个超级强大的运行时权限工具类,一行代码解决运行时权限
不多BB,直接上效果图
1、 Activity中使用运行时权限的Activity extend PermissionActivity;Fragment中使用运行时权限 Fragment extend PermissionFragment
2、重写requestPermission(String...permission)方法
### 使用依赖
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.Hu12037102:HuGePermission:1.2.0'
implementation 'com.github.Hu12037102:HuGePermission:1.2.5'
}
requestPermission(new OnPermissionsResult() {
@Override
public void onAllow(List<String> permissions) {
Toast.makeText(MainActivity.this,"申请权限成功!",Toast.LENGTH_SHORT).show();
}
@Override
public void onNoAllow(List<String> permissions) {
Toast.makeText(MainActivity.this,"部分权限申请失败,请重新申请",Toast.LENGTH_SHORT).show();
}
@Override
public void onForbid(List<String> permissions) {
showForbidPermissionDialog();
}
},
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_CALENDAR,
Manifest.permission.READ_CONTACTS,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.READ_SMS,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.CAMERA,
Manifest.permission.CALL_PHONE,
Manifest.permission.SEND_SMS);
java```