Allow capacitor web apps to use Google's MLKit Text recognizer and Barcode scanner
This plugin can scan the camera image for both Barcodes and Texts. It's up to you whether to enable the feature or not.
Important note
- This plugin does not stores previous hits/results. If multiple frames have the same content then the data will be provided to you.
npm install mlkit-text-barcode-scanner
npx cap sync
- Register the plugin in your main activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerPlugin(MLKitTextRecognizerPlugin.class);
}
- You can build your project
- After sync open your .xcworkspace file
- Open Pods target
- Select MLKitTextRecognition-LatinOCRResources Target
- Select your development team
- You can build your project
(Until further fix you need to select your team for this target after each sync)
See the example instructions here
startRecognizer(config: RecognizerConfig, callback: FoundRecognizerCallback) => Promise<CallbackID>
Starts the plugin with the passed configuration. Handles the permission checks internally.
The recognizer is not a one time event, it keeps firing the data to you until the user leaves the screen or you cancel the flow.
If permission is denied, then a custom exception will be thrown from the client
Param | Type |
---|---|
config |
RecognizerConfig |
callback |
FoundRecognizerCallback |
Returns: Promise<string>
killPlugin(callbackId: string) => Promise<void>
Param | Type |
---|---|
callbackId |
string |
Prop | Type | Description |
---|---|---|
isLoggingEnabled |
boolean |
Whether to show plugin logs. If non specified or disabled only errors will be shown |
barcodeScanner |
{ allow: boolean; } |
Barcode scanner configuration |
textRecognizer |
{ allow: boolean; } |
Text recognizer configuration |
Prop | Type |
---|---|
barcode |
BarCodeRecognizerData |
text |
TextRecognizerData |
Prop | Type |
---|---|
content |
string |
Prop | Type | Description |
---|---|---|
content |
string |
|
confidencePercentage |
number |
Only Android versions could tell the confidence percentage of the result |
string