运行时权限判断过程
1.判断是否大于等于6.0 (a)
----- 否直接调用
----- 是 ---判断是否拥有该权限(b)
-----是 直接调用
-----否 申请权限(c)
2.权限回调处理(d)
是否同意
----是 直接调用
----否 判断是否会弹出询问权限的对话框(如果用户拒绝了的话就不会)(f)
---是 再次申请权限(c)
---否 弹窗提示用户去设置处理
a.Build.VERSION.SDK_INT >= 23
b. PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
c. ActivityCompat.requestPermissions(MainActivity.this,new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS
}, CODE_REQUEST_STORAGE);
d. public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case CODE_REQUEST_STORAGE:
AppPermissionUtil.doNext(CODE_REQUEST_STORAGE, requestCode, grantResults, filePermissionCallback);
}
}
e.if (permissionCallback != null) {
if (requestCode == wt && grantResults != null && grantResults.length > 0) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
permissionCallback.onGetPermissionSuccess();
} else {
permissionCallback.onGetPermissionFailed();
}
}
}
f.ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
推荐一个权限插件
https://github.com/permissions-dispatcher/PermissionsDispatcher 注解方便好用