Hi, I have a question. Is there a library (the most used or the best…) that scans barcodes and QR codes on both Android and iOS?
The versions I have of the Ionic project are:
NodeJS: 12.21.0
Ionic CLI: 6.20.8
Ionic Framework: @ionic /angular 5.6.12
@angular /cli: 12.1.3
Capacitor CLI: 3.9.0
Thanks!
I know the following two Capacitor plugins for scanning barcodes and QR codes:
Capacitor Community Barcode Scanner
Capacitor ML Kit Barcode Scanning
The biggest difference between the two plugins is the SDK used to recognise the barcodes. The Capacitor Community Barcode Scanner plugin uses the ZXing decoder and the Capacitor ML Kit Barcode Scanning plugin uses the ML Kit from Google.
However, both supported only the current Capacitor version (4+).
Disclaimer : I am the maintainer of the second plugin.
Okay, thanks!
So, in my project with those versiones, will not work only because for Capacitor? Am I right?
Greetings.
Yes, you need to update your Capacitor version. However, you should also update your Capacitor version regardless of the plugin in order to comply with the current Play Store guidelines regarding the minimum SDK Targets (see Announcing Capacitor 4.0 ).
Hi Robin,
The ML Kit Barcode (maintained by you) works on Android 14, but it does not work on older devices (Android 11, 12, 13).
I followed the steps in Github. Am I missing something for older devices?
I cannot help you without any error message. Please create a GitHub issue with a minimal, reproducible example.
Just an update. Upon further Googling, I managed to find the solution.
This was the issue.
installGoogleBarcodeScannerModule
Solution provided here:
opened 04:38PM - 23 May 23 UTC
closed 02:18PM - 12 Jul 23 UTC
platform: android
bug/fix
package: barcode-scanning
### Plugin(s)
- [X] Barcode Scanning
- [ ] Translation
### Did you test the la… test version?
- [X] I use the latest version
### Platform(s)
- [X] Android
- [ ] iOS
- [ ] Web
### Current behavior
When calling the `scan(...)` the following error message appears in Android Studio:
```
scan failed.
com.google.mlkit.common.MlKitException: Failed to scan code.
at com.google.mlkit.vision.codescanner.internal.zze.zzc(com.google.android.gms:play-services-code-scanner@@16.0.0-beta3:4)
at com.google.mlkit.vision.codescanner.internal.zzf.onActivityResult(com.google.android.gms:play-services-code-scanner@@16.0.0-beta3:5)
at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:409)
at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:366)
at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:712)
at android.app.Activity.dispatchActivityResult(Activity.java:8951)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5987)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:6033)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8757)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
```
### Expected behavior
No exception.
### Reproduction
-
### Steps to reproduce
1. Call the `scan(...)` method on Android
Seems to be reproducible only on some devices (e.g. Samsung S21 with Android 13).
### Other information
_No response_
### Capacitor doctor
-
### Before submitting
- [X] I understand that incomplete issues (e.g. without reproduction) are closed.
1 Like