Easily integrate Google's ML Kit Document Scanner API into your Android app. This project offers a clean implementation, usage guide, and customization options for a seamless document scanning experience.
| Feature | Description |
|---|---|
| 📦 SDK | play-services-mlkit-document-scanner |
| 📥 Download Size | ~300KB |
| ⚡ Initialization | Slight delay on first use (models/UI are downloaded) |
| 🔧 Customization | Gallery import, page limits, scanner modes |
- Minimum SDK: 21+
- Dependencies:
- Google Maven repository required in
build.gradle - Kotlin + AndroidX + ML Kit Scanner
- Google Maven repository required in
Add the dependency for the ML Kit document scanner library to your module's app-level build.gradle file:
dependencies {
// ...
implementation 'com.google.android.gms:play-services-mlkit-document-scanner:16.0.0-beta1'
}
Customize the document scanner options:
val options = GmsDocumentScannerOptions.Builder()
.setGalleryImportAllowed(false)
.setPageLimit(2)
.setResultFormats(RESULT_FORMAT_JPEG, RESULT_FORMAT_PDF)
.setScannerMode(SCANNER_MODE_FULL)
.build()
val scanner = GmsDocumentScanning.getClient(options)
val scannerLauncher = registerForActivityResult(StartIntentSenderForResult()) { result ->
if (result.resultCode == RESULT_OK) {
val result = GmsDocumentScanningResult.fromActivityResultIntent(result.data)
result.getPages()?.let { pages ->
for (page in pages) {
val imageUri = pages.get(0).getImageUri()
}
}
result.getPdf()?.let { pdf ->
val pdfUri = pdf.getUri()
val pageCount = pdf.getPageCount()
}
}
}
scanner.getStartScanIntent(activity)
.addOnSuccessListener { intentSender ->
scannerLauncher.launch(IntentSenderRequest.Builder(intentSender).build())
}
.addOnFailureListener { exception ->
// Handle failure
}
- Clean MVVM architecture with unidirectional data flow.
- Loosely coupled layers for easy testing and scalability.
- UI communicates with ViewModel → ViewModel fetches data via Repository.
- ViewModel + DataBinding
- Uses Bindables for two-way data binding.
- Configuration changes are gracefully handled.
- Offline-first using Room
- Repository pattern ensures single source of truth
- Clean separation between local and external sources
- Repositories handle business logic and act as single source of truth.
- Offline-first design using local caching and potential future cloud integration.
More on modularization: Google Guide
By integrating ML Kit's Document Scanner, your app gains a seamless, native scanning experience powered by Google Play services. With flexible configuration and minimal setup, you can deliver high-quality scanning to your users.
If you like this project, please consider ⭐ starring the repo and following me for more cool Android projects!
☕ You can also support my work by buying me a coffee:
👨💻 Follow @shubhanshu24510 for more cool projects Copyright 2025 Shubhanshu Singh
Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0









