0

I have just tried the official example in my real phone.

https://github.com/react-native-image-picker/react-native-image-picker/tree/main/example

However, When I click "Select Image", it does not ask for any permission to gallery. It directly opens. What should I do to make it ask permission before opening gallery?

I have tried these lines at manifest, but they did not do anything:

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.ACTION_OPEN_DOCUMENT"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.GALLERY"/>

app view

funky-nd
  • 637
  • 1
  • 9
  • 25

1 Answers1

0

You can ask the permission using PermissionsAndroid like this example:

import {PermissionsAndroid, Platform} from 'react-native';

export const grantGalleryPermission = async () => {
  if (Platform.OS === 'ios') return true;
  const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE;
  const hasPermission = await PermissionsAndroid.check(permission);
  if (hasPermission) {
    return true;
  }
  const status = await PermissionsAndroid.request(permission);
  return status === 'granted';
}
Louay Sleman
  • 1,794
  • 2
  • 15
  • 39