@capgo/capacitor-document-scanner 8.3.10 → 8.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -29,6 +29,22 @@ npm install @capgo/capacitor-document-scanner
|
|
|
29
29
|
npx cap sync
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
## Important Notes
|
|
33
|
+
|
|
34
|
+
### Android Emulator Limitations
|
|
35
|
+
|
|
36
|
+
The ML Kit Document Scanner **does not work on Android emulators**. This is a limitation of Google Play Services and ML Kit on emulated devices. When testing your app:
|
|
37
|
+
|
|
38
|
+
- ✅ Use a **physical Android device** for testing document scanning
|
|
39
|
+
- ❌ Android emulators will show an error: "Document scanner is not supported on Android emulators"
|
|
40
|
+
|
|
41
|
+
This limitation is due to:
|
|
42
|
+
- Google Play Services compatibility issues with emulator environments
|
|
43
|
+
- ML Kit Document Scanner requiring actual hardware camera capabilities
|
|
44
|
+
- Emulators lacking the necessary ML Kit runtime components
|
|
45
|
+
|
|
46
|
+
**For development and testing, always use a real Android device.**
|
|
47
|
+
|
|
32
48
|
## Demo
|
|
33
49
|
|
|
34
50
|
### Scanning one note
|
package/android/build.gradle
CHANGED
|
@@ -3,6 +3,7 @@ ext {
|
|
|
3
3
|
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
4
|
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
5
|
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
playServicesBaseVersion = project.hasProperty('playServicesBaseVersion') ? rootProject.ext.playServicesBaseVersion : '18.5.0'
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
buildscript {
|
|
@@ -53,6 +54,7 @@ dependencies {
|
|
|
53
54
|
implementation project(':capacitor-android')
|
|
54
55
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
56
|
implementation "com.google.android.gms:play-services-mlkit-document-scanner:16.0.0"
|
|
57
|
+
implementation "com.google.android.gms:play-services-base:$playServicesBaseVersion"
|
|
56
58
|
testImplementation "junit:junit:$junitVersion"
|
|
57
59
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
58
60
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
@@ -23,6 +23,8 @@ import com.getcapacitor.Plugin;
|
|
|
23
23
|
import com.getcapacitor.PluginCall;
|
|
24
24
|
import com.getcapacitor.PluginMethod;
|
|
25
25
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
26
|
+
import com.google.android.gms.common.ConnectionResult;
|
|
27
|
+
import com.google.android.gms.common.GoogleApiAvailability;
|
|
26
28
|
import com.google.mlkit.vision.documentscanner.GmsDocumentScanner;
|
|
27
29
|
import com.google.mlkit.vision.documentscanner.GmsDocumentScannerOptions;
|
|
28
30
|
import com.google.mlkit.vision.documentscanner.GmsDocumentScanning;
|
|
@@ -93,7 +95,7 @@ public class DocumentScannerPlugin extends Plugin {
|
|
|
93
95
|
return;
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
// Check if running on emulator
|
|
98
|
+
// Check if running on emulator first (doesn't require activity reference)
|
|
97
99
|
if (isRunningOnEmulator()) {
|
|
98
100
|
call.reject(
|
|
99
101
|
"Document scanner is not supported on Android emulators. " +
|
|
@@ -109,6 +111,22 @@ public class DocumentScannerPlugin extends Plugin {
|
|
|
109
111
|
return;
|
|
110
112
|
}
|
|
111
113
|
|
|
114
|
+
// Check Google Play Services availability
|
|
115
|
+
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
|
|
116
|
+
int resultCode = apiAvailability.isGooglePlayServicesAvailable(activity);
|
|
117
|
+
if (resultCode != ConnectionResult.SUCCESS) {
|
|
118
|
+
StringBuilder errorMessage = new StringBuilder(
|
|
119
|
+
"The ML Kit Document Scanner requires Google Play Services, which is not available or needs an update. "
|
|
120
|
+
);
|
|
121
|
+
if (apiAvailability.isUserResolvableError(resultCode)) {
|
|
122
|
+
errorMessage.append("Please update Google Play Services and try again.");
|
|
123
|
+
} else {
|
|
124
|
+
errorMessage.append("This device may not support the document scanner.");
|
|
125
|
+
}
|
|
126
|
+
call.reject(errorMessage.toString());
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
112
130
|
int quality = clamp(call.getInt("croppedImageQuality", 100), 0, 100);
|
|
113
131
|
String responseType = normalizeResponseType(call.getString("responseType"));
|
|
114
132
|
int pageLimit = clamp(call.getInt("maxNumDocuments", 24), 1, 24);
|
|
@@ -419,22 +437,42 @@ public class DocumentScannerPlugin extends Plugin {
|
|
|
419
437
|
String hardware = Build.HARDWARE.toLowerCase(Locale.ROOT);
|
|
420
438
|
String board = Build.BOARD.toLowerCase(Locale.ROOT);
|
|
421
439
|
|
|
422
|
-
|
|
423
|
-
|
|
440
|
+
// Check for emulator characteristics
|
|
441
|
+
boolean isEmulator = (fingerprint.startsWith("generic") ||
|
|
424
442
|
fingerprint.startsWith("unknown") ||
|
|
443
|
+
fingerprint.contains("test-keys") ||
|
|
425
444
|
model.contains("google_sdk") ||
|
|
426
445
|
model.contains("emulator") ||
|
|
427
446
|
model.contains("android sdk built for x86") ||
|
|
447
|
+
model.contains("sdk_gphone") ||
|
|
428
448
|
manufacturer.contains("genymotion") ||
|
|
429
449
|
(brand.startsWith("generic") && device.startsWith("generic")) ||
|
|
430
450
|
"google_sdk".equals(product) ||
|
|
431
451
|
product.contains("sdk_gphone") ||
|
|
452
|
+
product.contains("sdk_google") ||
|
|
432
453
|
product.contains("emulator") ||
|
|
454
|
+
product.contains("vbox") ||
|
|
433
455
|
hardware.contains("ranchu") ||
|
|
434
456
|
hardware.contains("goldfish") ||
|
|
435
457
|
board.contains("ranchu") ||
|
|
436
|
-
board.contains("goldfish")
|
|
437
|
-
|
|
458
|
+
board.contains("goldfish") ||
|
|
459
|
+
board.contains("qemu"));
|
|
460
|
+
|
|
461
|
+
// Additional check: Build.SERIAL property for common emulator identifiers
|
|
462
|
+
// Emulators often have "emulator" or "unknown" in their serial number
|
|
463
|
+
if (!isEmulator) {
|
|
464
|
+
try {
|
|
465
|
+
String serial = Build.SERIAL;
|
|
466
|
+
if (serial != null) {
|
|
467
|
+
serial = serial.toLowerCase(Locale.ROOT);
|
|
468
|
+
isEmulator = serial.contains("emulator") || serial.equals("unknown");
|
|
469
|
+
}
|
|
470
|
+
} catch (SecurityException e) {
|
|
471
|
+
// Ignore if Build.SERIAL access is restricted (Android 8.0+)
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return isEmulator;
|
|
438
476
|
}
|
|
439
477
|
|
|
440
478
|
@PluginMethod
|
|
@@ -3,7 +3,7 @@ import Foundation
|
|
|
3
3
|
|
|
4
4
|
@objc(DocumentScannerPlugin)
|
|
5
5
|
public class DocumentScannerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
-
private let pluginVersion: String = "8.3.
|
|
6
|
+
private let pluginVersion: String = "8.3.11"
|
|
7
7
|
public let identifier = "DocumentScannerPlugin"
|
|
8
8
|
public let jsName = "DocumentScanner"
|
|
9
9
|
public let pluginMethods: [CAPPluginMethod] = [
|