Android M permission dialog not showing

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

I collect all the necessary permissions and then run

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

requiredPermissions contains the permissions I need as android.permission.WRITE_EXTERNAL_STORAGE .

This procedure definitely executes, since I have a log line in 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 is never displayed, not to mention the call to onRequestPermissionsResult ().

What am I doing wrong? Based on some lessons, I found that nothing was missing. I have only an emulator for testing, there is no physical device. This is the screen of the settings screen: Image

Maybe something else is worth mentioning: if I try to open an overview of installed applications from the main screen, I get only launcher3 has exited . I am not sure if this could be related.

Does anyone have an idea why he is not showing?

+44
android android-6.0-marshmallow permissions
Aug 07 '15 at 13:06
source share
24 answers

Based on a comment from Hilal (thanks a lot!): In my case, my application really uses tabhost, and permissions were requested from Activity inside tabhost. After starting a separate action that requests permission, it works.

+4
Feb 13 '17 at 17:16
source share

I had the same problem, but later I realized that I forgot to add permission to the manifest file. After adding the uses-permission tag, the system showed a dialog. Maybe it helps someone.

+73
Nov 29 '15 at 9:25
source share

I had the same problem because I used a negative value as REQUEST_CODE.

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

After using a positive value, the system displays a dialog. Hope this helps someone.

+11
Dec 23 '15 at 10:16
source share

add

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

in AndroidManifest.xml

Note. The permission you want to get. For example: android.permission.ACCESS_FINE_LOCATION, etc.

+8
Feb 03 '16 at 6:21
source share

I had the same problem. My problem was that I wrote the permission in the wrong place of the manifest. Make sure usage permissions are outside the application:

  <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.gms.samples.vision.face.photo" android:installLocation="auto" android:versionCode="1" android:versionName="1" > <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <application android:hardwareAccelerated="true" android:label="FacePhotoDemo" android:allowBackup="true" android:icon="@drawable/icon"> 
+7
Mar 30 '16 at 14:08
source share

It took me a whole day to find out what caused the problem. The initial answer helped me here: stack overflow

I fixed it by adding tools:remove="android:maxSdkVersion" as follows:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/> 
+5
Sep 18 '17 at 5:29 on
source share

I have the same problem and the problem is resolved after adding shouldShowRequestPermissionRationale as follows:

 if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, Manifest.permission.READ_CONTACTS)) { } else { ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.READ_CONTACTS}, MY_PERMISSIONS_REQUEST_READ_CONTACTS); } 
+2
Feb 26 '16 at 9:14
source share

I also encountered a situation where the permission dialog does not appear or the application crashes when using the <uses-permission-sdk23> , however the reason seems to be a system error for current 6.0 devices:

https://code.google.com/p/android/issues/detail?id=189841

Failure Exception:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity}: java.lang.NullPointerException: Attempt to get length of null array 
+1
Oct. 14 '15 at 16:00
source share

I did everything that was said in the answers above, but the dialog was not showing yet, and then I changed targetSdkVersion to 23 in gradle and appeared. Hope this helps someone.

+1
Feb 15 '16 at 12:54 on
source share

Permissions are organized by category, so non-critical are granted without displaying a dialog box.

I found this difficult way with permission to access the Internet, if you had this problem, and then going to a critical resolution like read_contacts will allow you to test the stream and show if the problem is non-critical, the rest.

Normal protection permissions are listed here.

+1
Mar 05 '16 at 23:40
source share

To add @ shanraisshan to the answer, the value of REQUEST_CODE must be greater than 0, and not just non-negative.

+1
Dec 07 '16 at 13:22
source share

In our code, it was a simple spelling mistake.

We had:

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

It should be:

 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
+1
Apr 7 '17 at 2:27 on
source share

After some searching time, you need to set the compileSdkVersion value to "android-MNC" or today to 23. This requires the Gradle build system, which seems to require Android Studio. At least I could not find a single guide on how to install it outside of Gradle files.

0
Aug 18 '15 at 13:34 on
source share
 @Override public final void validateRequestPermissionsRequestCode(int requestCode) { // We use 16 bits of the request code to encode the fragment id when // requesting permissions from a fragment. Hence, requestPermissions() // should validate the code against that but we cannot override it as we // can not then call super and also the ActivityCompat would call back to // this override. To handle this we use dependency inversion where we are // the validator of request codes when requesting permissions in // ActivityCompat. if (!mRequestedPermissionsFromFragment && requestCode != -1 && (requestCode & 0xffff0000) != 0) { throw new IllegalArgumentException("Can only use lower 16 bits for requestCode"); } } 
0
Apr 30 '16 at 2:00
source share

There was the same problem. Later I realized that we must declare each permission in the manifest (even if it is a subclass of the other). In my case, I announced

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

in my manifest and tried to access the user's rough location.

 ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) 

The problem is fixed, adding also rough resolution in the manifest.

 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
0
Aug 18 '16 at 4:58
source share

In the manifest, I changed

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

to

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

Maybe this helps.

0
Aug 25 '16 at 19:17
source share

Add permission to the manifest file.

0
Oct 13 '16 at 7:25
source share

Set targetSdkVersion to 22 .

0
Dec 19 '16 at 22:02
source share

had the same problem (i guess) and the solution removed

 import <app package>.Manifest; 

Android Studio is automatically imported at the top of the file and replaces it

 import android.Manifest; 

and started to work

0
Jan 17 '17 at 8:41
source share

In my case, the solution is the string itself

android.permission.READ_CONTACTS

I did Manifest.permission.READ_CONTACTS, which caused a silence error (marking the screen display).

Make sure this is correct.

0
Jan 18 '17 at 20:10
source share

If any of you have an application that modifies / modifies WRITE_SETTINGS and encounters this problem. Check CommonsWare Response to WRITE_SETTINGS Ambiguity

I ran into this problem for 2 weeks, and later realized that this problem was due to the fact that requestPermissions did not work to request permission from WRITE_SETTINGS . Hope this helps: D

0
Jul 19 '17 at 4:56 on
source share

In my case, I requested "ACCESS_COARSE_LOCATION" in my manifest file, and then requested permission "ACCESS_FINE_LOCATION" in the code, why the Permission Dialog did not open.

0
Aug 28 '17 at 8:04 on
source share

I made two calls to requestPermissions (), one after the other. This error message appeared in Logcat (note the spelling of the "request"):

 Can reqeust only one set of permissions at a time 

requestPermissions () is actually designed to simultaneously execute multiple requests; that for an array of String.

0
Sep 06 '17 at 10:11
source share

Change the final value of the constant to 1.

 private static final int REQUEST_PERMISSION_WRITE = 1; ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},REQUEST_PERMISSION_WRITE); 
0
08 Sep '17 at 18:34 on
source share



All Articles