androidreact-nativereact-native-linking

How to open android gallery app from React Native app


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.


Solution

  • 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,
          },
        });
      }
    });