5

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);
Sudip Podder
  • 830
  • 11
  • 25
user567
  • 3,712
  • 9
  • 47
  • 80

2 Answers2

3

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);
Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107
1

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.

Ashish Shukla
  • 1,027
  • 16
  • 36
  • 1
    Got the link for point 1. https://developer.android.com/about/versions/oreo/android-8.0-changes#rmp – Spring Breaker Sep 09 '19 at 10:29
  • @Ashish Shukla suppose clicked clicked Never Ask Again option after next time how to show request permission dialog? – krishna May 24 '22 at 17:36
  • @krishna Use this link : https://medium.com/@begalesagar/method-to-detect-if-user-has-selected-dont-ask-again-while-requesting-for-permission-921b95ded536 – Ashish Shukla May 25 '22 at 08:43