系统不再弹窗让用户选择的权限, 将被视为 永久被拒绝的权限

  1. implementation 'androidx.appcompat:appcompat:1.2.0'
  2. implementation 'me.luzhuo.android:lib_permission:1.1.3-SNAPSHOT'
  1. Permission.request(this, new PermissionCallback() {
  2. @Override
  3. public void onRequst(boolean isAllGranted, List<String> denieds, List<String> foreverDenieds) {
  4. if(isAllGranted) Toast.makeText(MainActivity.this, "权限通过", Toast.LENGTH_SHORT).show();
  5. else Toast.makeText(MainActivity.this, "权限拒绝", Toast.LENGTH_SHORT).show();
  6. }
  7. @Override
  8. public void onGranted() {
  9. Toast.makeText(MainActivity.this, "所有权限都通过", Toast.LENGTH_SHORT).show();
  10. }
  11. @Override
  12. public void onDenieds(List<String> denieds) {
  13. Toast.makeText(MainActivity.this, "有权限被拒绝, 不含永久拒绝的权限", Toast.LENGTH_SHORT).show();
  14. }
  15. @Override
  16. public void onForeverDenieds(List<String> foreverDenieds) {
  17. Toast.makeText(MainActivity.this, "永久被拒绝的权限, 不含非永久拒绝的权限", Toast.LENGTH_SHORT).show();
  18. }
  19. }, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA);

1. 权限详情页

当某个权限被用户永久禁止后, 需要用户跳到权限详情页, 手动打开某个权限

Screenshot_20220222_202726.jpg

  1. private void gotoPermissionDetail() {
  2. Intent intent = new Intent();
  3. intent.setAction(ACTION_APPLICATION_DETAILS_SETTINGS);
  4. intent.setData(Uri.parse("package:" + this.getPackageName()));
  5. this.startActivityForResult(intent, 0x001);
  6. }
  7. @Override
  8. protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  9. super.onActivityResult(requestCode, resultCode, data);
  10. if (requestCode == 0x001) {
  11. Log.e(TAG, "" + ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA));
  12. }
  13. }

2. 常见问题

1. 报 java.lang.IllegalStateException: FragmentManager is already executing transactions

a41a31dc72bc29283e9977791bd01b7.png
放到Activity里运行