2

enter image description hereI want to download a file using DownloadManager. And DownloadManager wants to WRITE_EXTERNAL_STORAGE permission. I have included the WRITE_EXTERNAL_STORAGE permission in AndroidManifest.xml. Furthermore, I try to take this permission on runtime.

onRequestPermissionsResult callback is called immediately after the request permission. The request permission popup didn't display.

However, the value of the grantResult[0] on the onRequestPermissionsResult is PERMISSION_DENIED. But THE PERMISSION POPUP ISN'T EVEN SHOWN.

I check the permission like this:

public  boolean isStoragePermissionGranted() {
    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(getContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Log.v(TAG,"Permission is granted");
            return true;
        } else {

            Log.v(TAG,"Permission is revoked");
            ActivityCompat.requestPermissions(getActivity(), new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_PERMISSION_REQUEST_CODE);
            return false;
        }
    }
    else {
        Log.v(TAG,"Permission is granted");
        return true;
    }
}

And this is callback of the permission request:

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        case WRITE_EXTERNAL_PERMISSION_REQUEST_CODE: {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                downloadFile();
            }
            break;
        }
    }
}

When I have tried for READ_EXTERNAL_STORAGE permission, I could take that permission but it didn't work for WRITE_EXTERNAL_STORAGE permission.

Also, I have tried @MetaSnarf's solution. But nothing has changed.

Have you any idea about this situation?

Selin
  • 616
  • 2
  • 9
  • 23

1 Answers1

7

One of your dependency can cause that problem. You can replace permission in your manifest.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />
mertsimsek
  • 266
  • 2
  • 10
  • @mertsimsek Tried to debug this for hours... thanks! Do you have an idea how to find out which dependency caused it, or could you explain where something goes wrong? I'm not sure what to look for. – xian Apr 08 '19 at 15:21
  • Found it - The AppLovin SDK added a maxSdkVersion.. Thanks again! :) – xian Apr 08 '19 at 15:30