Android 使用Zxing报错:Channel is unrecoverably broken and will be disposed!

Litchi 2020-06-05

使用Zxing的扫描二维码库,修改成从相册识别二维码图片,根据网上的demo修改,继而在我使用的fragment报错Channel is unrecoverably broken and will be disposed!

网上demo写的原始代码:????

在使用的fragment重写onActivityResult中:

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == Constants.REQ_QR_CODE && resultCode == RESULT_CODE_QR_SCAN && data != null) {
  ...
  }
}
修改:??????
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == AppConfig.CAMERA_SCAN_QRCODE_REQUEST && resultCode == RESULT_OK && data != null){
  ...
  }
}
结论:所对应的的requestCode和resultCode要一一对应,否则接收不到相应的回传值,会有空指针报错!继而报出此错误。

相关推荐