October 26, 2024
Chicago 12, Melborne City, USA
java

Request for permission (Pop – up) dialog is not showing in Android


I have the following register initialized in onCreate method of an AppCompatActivity class:

ActivityResultLauncher<String> requestPermissionLauncher =
                registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
                    if (!isGranted) {
                        Toasty.error(context, "Can't continue without the required permissions", Toast.LENGTH_LONG).show();
                    }
                });

then when a button is clicked the following code checks for the permission:

if (ActivityCompat.checkSelfPermission(context,
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
            return;
        }

However, the Request for permission – the Pop-up dialog is not showing and I am getting a Toast notification as above as permission is found not granted.

The app is running on a physical device with Android 14. I have checked the permission flag of my device using "adb shell dumpsys package MY_PACAKGE_NAME" command and have got the flags as –

android.permission.READ_EXTERNAL_STORAGE: granted=false, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED|RESTRICTION_INSTALLER_EXEMPT]

The above indicates – the required permission request has not been denied multiple times due to which the pop-up dialog might not show anymore. The flags "USER_SET | USER_FIXED" is not found which means similar to "don’t ask again" as mentioned in this google developer documentation link.

Both my app manifest and the merged manifest has the following –

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

My build.gradle file has the following –

minSdkVersion 28
targetSdkVersion 34

I have tried with clear all data, then complete uninstalling of the app and reinstalling the app with no results.

The pop-up is showing on Emulator running with Android 12L.

I have tried enabling all the permissions required from the "App Info > App permissions" – still my app fails to read external storage i.e. all the images from the external media bucket (from other shared folders – from other apps like facebook, whatsapp, download folder etc. Only DCIM camera folder pictures are being read by my app).



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video