Allow capacitor web apps to use MLKit's Text recognizer and it's BarCode scanner
npm install mlkit-text-barcode-scannerAllow 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.
``bash`
npm install mlkit-text-barcode-scanner
npx cap sync
(kotlin)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerPlugin(MLKitTextRecognizerPlugin.class);
}
`
2. You can build your project$3
1. After sync open your .xcworkspace file
2. Open Pods target
3. Select MLKitTextRecognition-LatinOCRResources Target
4. Select your development team
5. You can build your project(Until further fix you need to select your team for this target after each sync)
Example
See the example instructions here$3
#### Source:
!Source image#### Android result:
!Android text result
#### iOS result:
!iOS text result
$3
#### Source:
!Source image#### Android result:
!Android barcode result
#### iOS result:
!iOS barcode result
API
startRecognizer(...)
* killPlugin(...)
* Interfaces
* Type Aliases
$3
`typescript
startRecognizer(config: RecognizerConfig, callback: FoundRecognizerCallback) => Promise
`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>
--------------------
$3
`typescript
killPlugin(callbackId: string) => Promise
`| Param | Type |
| ---------------- | ------------------- |
|
callbackId | string |--------------------
$3
#### RecognizerConfig
| 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 |
#### FoundRecognizerCallback
| Prop | Type |
| ------------- | ----------------------------------------------------------------------- |
|
barcode | BarCodeRecognizerData |
| text | TextRecognizerData |
#### BarCodeRecognizerData
| Prop | Type |
| ------------- | ------------------- |
|
content | string |
#### TextRecognizerData
| Prop | Type | Description |
| -------------------------- | ------------------- | ------------------------------------------------------------------------ |
|
content | string | |
| confidencePercentage` | number | Only Android versions could tell the confidence percentage of the result |
#### CallbackID
string