【问题标题】:react-native-camera not firing on Androidreact-native-camera 未在 Android 上触发
【发布时间】:2021-07-24 22:33:33
【问题描述】:

我正在使用 react-native-camera 扫描条形码。在我开始开发的 iOS 上,一切都按预期运行。但在 Android 上,当条形码与相机对焦时,它不会触发 onBarcodeRead

相关代码如下:

<View style={styles.container}>
        <RNCamera
          ref={(ref) => {
            setCamera(ref);
          }}
          aspect={1}
          style={styles.preview}
          type={RNCamera.Constants.Type.back}
          flashMode={RNCamera.Constants.FlashMode.on}
          captureAudio={false}
          onBarCodeRead={processBarcode}
          androidCameraPermissionOptions={{
            title: 'Permission to use camera',
            message: 'We need your permission to use your camera',
            buttonPositive: 'Ok',
            buttonNegative: 'Cancel',
          }}>
          <View>{mainInteractionElement}</View>
        </RNCamera>
      </View>

processBarcode 函数不会在 Android 上触发。我已经阅读了所有(旧)关于条码扫描无法在 Android 上运行的答案,但没有任何描述对我有帮助(例如升级到最新版本、设置纵横比……)。

谁有解决办法?

感谢和问候

【问题讨论】:

  • 你为什么不用Expo Camera
  • 因为我没有使用 Expo。我认为 Expo Camera 不使用 Expo 就无法工作,对吧?
  • 您也可以在 Bare Workflow 中使用它。
  • 好的,谢谢!当然,如果可能的话,我宁愿使用 react-native-camera,因为我已经围绕它构建了一个很大的功能集,所以如果有人也有 react-native-camera 的解决方案,我会很高兴

标签: android react-native react-native-android barcode-scanner react-native-camera


【解决方案1】:

实际上我没有让它运行。最后,我决定在 iOS 上使用onBarCodeRead,在 Android 上使用onGoogleVisionBarcodesDetected。这是我让它在两个平台上运行的唯一方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多