Android M permission dialog not showing

I'm currently trying to adapt my application to the new permissions model of Android M.

I'm collecting all the permissions I require, then run

Log.i("Permissions", "Requesting permissions: " + permissions);
requestPermissions(requiredPermissions.toArray(new String[requiredPermissions.size()]), requestCodeForPermissions);

requiredPermissions holds the permissions I need like android.permission.WRITE_EXTERNAL_STORAGE.

That routine is definitely executed as I have the Log line in the logcat:

08-07 12:52:46.469: I/Permissions(1674): Requesting permissions: android.permission.RECEIVE_BOOT_COMPLETED; android.permission.WRITE_EXTERNAL_STORAGE

But the permissions dialog never shows, let alone is onRequestPermissionsResult() called.

What am I doing wrong? Based on some tutorials I found I'm not missing anything. I only have the emulator for testing, no physical device. This is the about screen from settings: Image

It might be worth mentioning something else: If I try to open the overview of installed apps from the home screen I only get launcher3 has exited. I'm not sure if that might be related.

Does anybody have an idea why it's not showing?


Solution 1:

I experienced the same issue but later I realized I forgot to add the permission to the manifest file. After adding the uses-permission tag, the system showed the dialog. Maybe helps someone.

Solution 2:

It took my whole day to find out what caused the problem. The original answer helped me.

I fixed by adding tools:remove="android:maxSdkVersion" like this:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>

Solution 3:

I experienced the same issue because I was using the negative value as a REQUEST_CODE.

requestPermissions(new String[]{android.Manifest.permission.CAMERA}, -1)

After using positive value, the system showed the dialog. Hope it helps someone.

Solution 4:

Based on the comment from Hilal (thanks a lot!): In my case my app is indeed using tabhost and the permissions were requested from an Activity inside the tabhost. After starting a separate activity that requests the permissions it is working.