Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Required permission was denied!" when requesting WRITE_EXTERNAL_STORAGE

I am trying to request WRITE_EXTERNAL_STORAGE permission on Android 10. I do that using the following code:

ArrayList<String> permissions = new ArrayList<>();
if (this.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
}
if (this.checkSelfPermission(ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
        this.checkSelfPermission(ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    permissions.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
}
if (this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
    permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (permissions.size() > 0) requestPermissions(permissions.toArray(new String[0]), PERMISSION_REQUEST_FINE_LOCATION);

Here is the manifest

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

All other permissions work except WRITE_EXTERNAL_STORAGE. When I try to request it, it does not display any dialog for confirming permission, but it simply denies it. Why and how can I fix it?

like image 225
Miha Bogataj Avatar asked Oct 22 '25 02:10

Miha Bogataj


1 Answers

I have discovered the solution, however the cause of the problem is still a mystery to me. If anyone has an explination, it would be greatly appreciated. Basically my issue is a duplicate of this issue. All I had to do is to change the following line from

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

to

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

What does tools:node="replace" do?

like image 104
Miha Bogataj Avatar answered Oct 24 '25 18:10

Miha Bogataj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!