【问题标题】:React-native-image-picker crashes in Android 11React-native-image-picker 在 Android 11 中崩溃
【发布时间】:2022-11-08 17:32:22
【问题描述】:

我在我的项目中使用了 react-native-image-picker。它在低于 Android 11 的 android 手机中运行良好,但应用程序在 android 11 中崩溃而不显示 logcat。 launchImageLibrary 正在按预期工作,但 launchCamera 正在崩溃应用程序。我也在android清单文件中添加了权限,即

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

但仍然没有运气。

【问题讨论】:

    标签: react-native


    【解决方案1】:

    尝试删除

    <uses-permission android:name="android.permission.CAMERA" />
    

    图像选择器不需要权限

    【讨论】:

      【解决方案2】:

      我通过在 launchImageLibrary/launchCamera 中添加 await 来修复它 我已添加代码供您参考

      const openCamera = async () => { 
      let options = { quality: 5, maxWidth: 500, maxHeight: 500, includeBase64: true, mediaType: 'photo', noData: true, };
      
      await launchCamera(options, response => { 
      if (response.didCancel) { 
      console.log('Cancelled');
      } else if (response.error) { 
      console.log('Error', response.errorMessage);
      } else { 
      console.log(response); 
      setFilePath(response.uri); 
      setBase64('data:image/png;base64,' + response.base64); } });
      };
      

      【讨论】:

        猜你喜欢
        • 2020-01-07
        • 1970-01-01
        • 2021-10-20
        • 1970-01-01
        • 2020-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-21
        相关资源
        最近更新 更多