2

I'm trying to give an Android app the WRITE_EXTERNAL_STORAGE but it doesn't seem to be given the permission in the emulator. The Android.manifest looks like follows:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

As you can see, I've clearly android.permission.WRITE_EXTERNAL_STORAGE. Anyone know why the permission is still not given? I've tried various emulators (API 24, 26, 28).

Any thought appreciated.

EDIT: My project has quite a few dependencies:

"dependencies": {
    "moment": "^2.22.0",
    "react": "16.0.0",
    "react-native": "0.51.0",
    "react-native-background-timer": "^2.0.1",
    "react-native-camera": "^1.1.4",
    "react-native-code-push": "^5.3.2",
    "react-native-elements": "^0.19.0",
    "react-native-google-analytics-bridge": "^5.6.3",
    "react-native-modal-dropdown": "^0.6.2",
    "react-native-photo-upload": "^1.2.0",
    "react-native-router-flux": "^4.0.0-beta.28",
    "react-native-star-rating": "^1.0.9",
    "react-native-ui-kitten": "^3.0.0",
    "react-native-vector-icons": "^4.5.0",
    "recyclerlistview": "^1.3.1",
    "react-native-wheel-picker": "^2.0.0",
  },
John M.
  • 2,642
  • 7
  • 26
  • 55

3 Answers3

5

I've fixed it with PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE).

John M.
  • 2,642
  • 7
  • 26
  • 55
0

Have you tried setting:

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

Taken from: WRITE_EXTERNAL_STORAGE not working on lollipop even though it's set in the manifest

or even this:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />
Liam
  • 439
  • 1
  • 4
  • 26
  • I'm indeed using a few other packages. Perhaps the cause of the issue is the same, but these new permission settings can't seem to fix my problem. – John M. Jun 11 '18 at 16:04
  • What packages are you using? – Liam Jun 11 '18 at 16:07
  • I've got quite. a few dependencies. Please see update. – John M. Jun 11 '18 at 16:14
  • Try this: Try this: https://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it. They say on SDK >23, you have to request certain permissions i.e. ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.SEND_SMS},1); – Liam Jun 11 '18 at 16:18
  • I'm aware of that, but [this project](https://github.com/react-native-community/rncamera-example/) has `targetSdkVersion=26` and doesn't need to ask for the storage permissions at run-time to get the permissions though. Perhaps RN is meant to handle the permissions? – John M. Jun 11 '18 at 16:26
0

Appranetly SDK > 23 needs a require permission even if specified for certain things.

https://developer.android.com/training/permissions/requesting

private static final int PERMISSION_WRITE_REQUEST_CODE = 1;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {

    if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
            == PackageManager.PERMISSION_DENIED) {

        Log.d("WritePermission", "No write permission given. Requesting...");
         ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                PERMISSION_WRITE_REQUEST_CODE);
    }
}
Liam
  • 439
  • 1
  • 4
  • 26