skip to Main Content

I’m working on a React Native application (version 0.74) and am experiencing issues with the WRITE_EXTERNAL_STORAGE permission on Android API 33+ (Android 13+). As per the new permission model introduced in Android 13, WRITE_EXTERNAL_STORAGE is deprecated .The permission WRITE_EXTERNAL_STORAGE seems to be ineffective, and my app cannot write to or access external storage as expected. The permission request does not seem to succeed, and file operations fail.

Details:
React Native Version: 0.74
Android API Level: 33+
Android Manifest Entries:xml
I’m using react-native-permissions to request permissions

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

const writeStorageGranted = await request(PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE);
          if (writeStorageGranted !== RESULTS.GRANTED) {
            console.log('Write External Storage permission denied');
            Alert.alert(
              'Permission Denied',
              "This app won't work without write storage permission. Please enable it in the app settings.",
              [
                {
                  text: 'OK',
                  onPress: () => Linking.openSettings()
                }
              ],
              { cancelable: false }
            );
            return;
          }
          console.log('Write External Storage permission granted');

Actual Behaviour:

The permission request ignored, and file operations that require external storage access do not work. Permission Popup not coming on Android API Level: 33+.It worked in below versions

Expected Behavior

The app should be able to request and be granted permission to write to external storage, allowing file operations to proceed as intended.

2

Answers


  1. In react native new update 0.74 version don’t need to ask WRITE_EXTERNAL_STORAGE permission. You can save files directly in storage.

    Login or Signup to reply.
  2. Documentation from https://developer.android.com/training/data-storage/shared/media#storage-permission states:

    If you are just accessing your own media files, no permissions are required. You don’t require any storage-related permissions on Android 10 or later devices in order to view and edit media files owned by your app, including ones found in the Media Store. gathering of downloads. For example, if you’re creating a camera app, you don’t need to ask for rights related to storage because your app is the owner of the photographs that you’re uploading to the media store.

    As of Android 10, requesting permission to access files from storage is no longer possible. Functions flawlessly with a variety of files (pdfs, excels, etc.) on my Android 13 app without requiring any permissions. Thus, for SDK versions lower than 10, all you have to do is request READ_EXTERNAL_STORAGE permission.

    However, you should request permission from your list if you require specific files.

    Additionally, check out https://developer.android.com/reference/android/provider/MediaStore for media storage kinds.

    Regarding WRITE_EXTERNAL_STORAGE, since sdkVersion=29, you don’t need it.

    EDIT: I wanted to add the following as I was reworking my app:

    Depending on what your app needs to do, I have removed all storage permissions from it (with the exception of WRITE_EXTERNAL_STORAGE, which is still required for SDK versions lower than 29). Instead, I only use ACTION_OPEN_DOCUMENT and ACTION_OPEN_DOCUMENT_TREE to access any type of file (though not system folders; ACTION_OPEN_DOCUMENT_TREE does not have access to download folders).

    This is how I’m using permissions now:

    export const checkAndroidPermission = async () => {
      if (Platform.OS === "android" && Platform.Version < 33) {
        const granted = await PermissionsAndroid.requestMultiple([
          "android.permission.CAMERA",
          "android.permission.WRITE_EXTERNAL_STORAGE"
        ]);
        if (
          granted["android.permission.CAMERA"] !== "granted" ||
          granted["android.permission.WRITE_EXTERNAL_STORAGE"] !== "granted"
        ) {
          throw new Error("Required permission not granted");
        }
      }
    };
    export const checkAndroidPermissionCameraRoll = async () => {
      if (Platform.OS === "android" && Platform.Version < 33) {
        const granted = await PermissionsAndroid.requestMultiple([
          "android.permission.WRITE_EXTERNAL_STORAGE",
          "android.permission.READ_EXTERNAL_STORAGE"
        ]);
        if (
          granted["android.permission.WRITE_EXTERNAL_STORAGE"] !== "granted" ||
          granted["android.permission.READ_EXTERNAL_STORAGE"] !== "granted"
        ) {
          throw new Error("Required permission not granted");
        }
      }
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search