系统不再弹窗让用户选择的权限, 将被视为 永久被拒绝的权限
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'me.luzhuo.android:lib_permission:1.1.3-SNAPSHOT'
Permission.request(this, new PermissionCallback() {
@Override
public void onRequst(boolean isAllGranted, List<String> denieds, List<String> foreverDenieds) {
if(isAllGranted) Toast.makeText(MainActivity.this, "权限通过", Toast.LENGTH_SHORT).show();
else Toast.makeText(MainActivity.this, "权限拒绝", Toast.LENGTH_SHORT).show();
}
@Override
public void onGranted() {
Toast.makeText(MainActivity.this, "所有权限都通过", Toast.LENGTH_SHORT).show();
}
@Override
public void onDenieds(List<String> denieds) {
Toast.makeText(MainActivity.this, "有权限被拒绝, 不含永久拒绝的权限", Toast.LENGTH_SHORT).show();
}
@Override
public void onForeverDenieds(List<String> foreverDenieds) {
Toast.makeText(MainActivity.this, "永久被拒绝的权限, 不含非永久拒绝的权限", Toast.LENGTH_SHORT).show();
}
}, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA);
1. 权限详情页
当某个权限被用户永久禁止后, 需要用户跳到权限详情页, 手动打开某个权限
private void gotoPermissionDetail() {
Intent intent = new Intent();
intent.setAction(ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + this.getPackageName()));
this.startActivityForResult(intent, 0x001);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0x001) {
Log.e(TAG, "" + ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA));
}
}
2. 常见问题
1. 报 java.lang.IllegalStateException: FragmentManager is already executing transactions
放到Activity里运行