I 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?
One of your dependency can cause that problem. You can replace permission in your manifest.