user567
user567

Reputation: 3862

RequestPermissions not showing a dialog box

I found a lot of similar topics with the same threat but I still can't find a solution for my problem. I wrote this code to grant the writing permission to the app but there is no dialog box showing. I get in the monitor the No writing permission messages.

if(ContextCompat.checkSelfPermission(getContext(),Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {
Log.i("permissions", "No writing permission");

ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 225);

I added the permission in the AndroidManifest fils

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

Changed the target sdk targetSdkVersion 23, and I am using android 6.0.1.

Edit: I also tied this code but it still not working

requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 225);

Upvotes: 5

Views: 8463

Answers (2)

Ashish Shukla
Ashish Shukla

Reputation: 1047

RequestPermissions Dialog will not be shown only in below 2 cases on device >= 6.0:

1) Either you have already given permission to the any of the Dangerous Permissions within the Category you are asking for.

2) You had clicked Never Ask Again checkbox when the dialog had shown previously.

Upvotes: 1

Murat Karag&#246;z
Murat Karag&#246;z

Reputation: 37624

I had a similiar case. Do not try to call it with ActivityCompat from a Fragment. Instead use the given requestPermissions method from the Fragment e.g.

 requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 225);

Upvotes: 3

Related Questions