The ML Kit Document Scanner models, logic, and UI are dynamically downloaded by Google Play services. Because of this, the scanner might not be available on the first use.
To ensure a smooth user experience, you should:
- Check if the module is available using
isGoogleDocumentScannerModuleAvailable(). - If not available, trigger the installation using
installGoogleDocumentScannerModule(). - Listen to the
googleDocumentScannerModuleInstallProgress event to provide progress updates to the user.
Note: This plugin is only available on Android via Google Play services. All methods will reject on other platforms.
// Example workflow for checking and installing the module
const available = await DocumentScanner.isGoogleDocumentScannerModuleAvailable();
if (!available) {
// Listen for progress updates
const listener = await DocumentScanner.addListener('googleDocumentScannerModuleInstallProgress', (info) => {
console.log('Installation progress:', info);
});
try {
await DocumentScanner.installGoogleDocumentScannerModule();
console.log('Installation complete');
} catch (err) {
console.error('Installation failed', err);
} finally {
listener.remove();
}
}