【问题标题】:How to open android gallery app from React Native app如何从 React Native 应用程序打开 android 图库应用程序
【发布时间】:2021-08-10 10:09:25
【问题描述】:

我在使用 Android 设备上的链接打开图库时遇到问题。它在 iOS 上完美运行。 我正在使用这个。

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");
 }
}

android上弹出弹窗,选择照片后出现黑屏here is the screenshot for the same.

【问题讨论】:

标签: android react-native react-native-android react-native-linking


【解决方案1】:

你可以使用这个包 https://github.com/react-native-image-picker/react-native-image-picker

这个包有可以用来打开画廊和选择图像的方法! 这个方法launchImageLibrary(options?, callback)对此很有用。

这里是使用此方法的示例:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    • 2020-12-06
    • 2013-10-07
    • 2020-09-06
    • 1970-01-01
    相关资源
    最近更新 更多