4

I'm using react-native-camera-roll/camera-roll@5.2.0 in my React Native app. For Android 13, the READ_EXTERNAL_STORAGE permission has been replaced by READ_MEDIA_IMAGES. I use the following code to check if permission has been granted:

const permission = Platform.Version >= 33 ? PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES : PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE;

const hasPermission = await PermissionsAndroid.check(permission);

However, PermissionsAndroid.PERMISSIONS doesn't contain READ_MEDIA_IMAGES, so permission is undefined. Passing undefined to PermissionsAndroid.check() makes the app hang.

What I Want To Know:

I'm using react-native@0.65.3. PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES doesn't become available until 0.70, so unless I update to 0.70, permission will always be undefined. How can I work around this?

gkeenley
  • 6,088
  • 8
  • 54
  • 129

1 Answers1

2

One of the solutions is to use the separate well maintained library for permissions handling called https://github.com/zoontek/react-native-permissions

If you want to get it from RN it should be included in 0.71 based on this PR https://github.com/facebook/react-native/commit/0a854c7c8b7ffc382c43fa460651a4b4de34c3c7

Based on PR above you also can create a patch from your local changes using https://github.com/ds300/patch-package. However, if you want to use patched version of RN you should follow this instruction https://reactnative.dev/contributing/how-to-build-from-source

Kirill Novikov
  • 2,576
  • 4
  • 20
  • 33
  • I'm using react-native-permissions now, thanks! Could you tell me what the difference is between using react-native-permissions for Android and using PermissionsAndroid from RN? – gkeenley Jan 05 '23 at 19:04
  • @gkeenley this module provides unified abstraction and because it is a separate module, you don't need to think about the RN version. You can read more about it https://reactnative.dev/blog/2019/07/03/version-60#lean-core-removals – Kirill Novikov Jan 05 '23 at 19:28