URL: bitpay/cordova-plugin-qrscanner#132
-
Add QR Scanner to support EAN-13, CODE-128, CODE-39.
-
Fix NulPointerException crashed in android.
Tested with: cordova-android: 11.0.0, cordova-ios: 6.3.0
- Uninstall original bitpay code if installed
npm uninstall --save cordova-plugin-qrscanner
- install modernize version (2022 May 6) to work with cordova-android v11.0.0
npm install --save https://github.com/jacobg/cordova-plugin-qrscanner#modernize
- install @ionic-native/qr-scanner@4
npm install --save @ionic-native/qr-scanner@4
-
Place all files under "hooks/jacobg-cordova-plugin-qrscanner/".
-
Add below in "config.xml":
<platform name="android">
<hook src="hooks/jacobg-cordova-plugin-qrscanner/android.js" type="after_prepare" ></hook>
</platform>
<platform name="ios">
<hook src="hooks/jacobg-cordova-plugin-qrscanner/ios.js" type="after_prepare" ></hook>
</platform>
<preference name="UseSwiftLanguageVersion" value="5" ></preference>
PATH: platforms/android/app/src/main/java/com/bitpay/cordova/qrscanner/QRScanner.java
Available Code Format: https://zxing.github.io/zxing/apidocs/com/google/zxing/BarcodeFormat.html
[FIND]
formatList.add(BarcodeFormat.QR_CODE);
[ADD_BELOW]
formatList.add(BarcodeFormat.EAN_13);
formatList.add(BarcodeFormat.CODE_128);
formatList.add(BarcodeFormat.CODE_39);
FIX: When accessing the parent of mBarcodeView, in some cases the NulPointerException crashed (MIUI Global 14 series) (by @mrFloony)
[FIND]
((ViewGroup) mBarcodeView.getParent()).removeView(mBarcodeView);
[REPLACE_WITH]
ViewGroup parent = ((ViewGroup) mBarcodeView.getParent());
if (parent != null) {
parent.removeView(mBarcodeView);
}
PATH: platforms/ios/[APP_NAME]/Plugins/cordova-plugin-qrscanner/QRScanner.swift"
Available Code Format: https://developer.apple.com/documentation/avfoundation/avmetadataobject/objecttype
[FIND]
metaOutput!.metadataObjectTypes = [AVMetadataObject.ObjectType.qr]
[REPLACE]
metaOutput!.metadataObjectTypes = [AVMetadataObject.ObjectType.qr, AVMetadataObject.ObjectType.ean13, AVMetadataObject.ObjectType.code128, AVMetadataObject.ObjectType.code39]
[FIND]
if found.type == AVMetadataObject.ObjectType.qr && found.stringValue != nil {
[REPLACE]
if ((found.type == AVMetadataObject.ObjectType.qr || found.type == AVMetadataObject.ObjectType.ean13 || found.type == AVMetadataObject.ObjectType.code128 || found.type == AVMetadataObject.ObjectType.code39) && found.stringValue != nil) {
https://github.com/bitpay/cordova-plugin-qrscanner/ https://github.com/jacobg/cordova-plugin-qrscanner#modernize