0

I am having trouble while opening the gallery using linking on android devices. It works perfectly on iOS. I am using this.

openPhotos = () =>{
switch(Platform.OS){
  case "ios":
    Linking.openURL("photos-redirect://");
  break;
  case "android":
    Linking.openURL("content://media/internal/images/media");
  break;
  default:
    console.log("Could not open gallery app");
 }
}

A pop is shown on android, and after selecting photos, a black screen appears.here is the screenshot for the same.

Ashish Prasad
  • 116
  • 1
  • 2
  • 14
  • Maybe this can help: https://github.com/react-native-image-picker/react-native-image-picker – Shubham Raitka Aug 10 '21 at 10:32
  • My motive was to open the gallery to view recently clicked images for a camera application and reduce the code implementation. It seems that I have to use this package and design a gallery component myself. Thanks for your guidance. – Ashish Prasad Aug 19 '21 at 18:21

1 Answers1

1

You can use this package https://github.com/react-native-image-picker/react-native-image-picker

This package have methods you can use to open gallery and select an image! This method launchImageLibrary(options?, callback) is useful for this.

Here an example for using this method:

RNImagePicker.launchImageLibrary({}, (response) => {
  if (response.didCancel) {
    // user cancel image selection
  } else if (response.error) {
    // error
  } else {
    // her you access the image with response object
    console.log(response);
    this.setState({
      image: {
        uri: response.uri,
      },
    });
  }
});
Mohamadamin
  • 564
  • 5
  • 16