๐Ÿง  Android AI Projects and Production

On-Device Image and Text Processing on Android

Many useful AI features need no cloud calls at all. ML Kit runs text recognition, image labeling, translation and more directly on the device: fast, private and free. Here's a practical tour with Kotlin and CameraX.

โœ๏ธ Yunok Tech ๐Ÿ“… Updated โฑ 3 min read ๐ŸŽฏ Intermediate
On this page
  1. What's available
  2. A camera pipeline
  3. Text recognition from a photo
  4. Live analysis with CameraX
  5. Language: ID, translation, entities
  6. Best practices
  7. Frequently asked questions
  8. Conclusion

ML Kit's vision and language APIs use compact, task-specific models. They run in milliseconds, work offline, and keep data on the phone, often making them a better first choice than an LLM. See LLMs vs Traditional ML.

What's available

APIDoesExample feature
Text recognitionOCR for Latin, Devanagari, Chinese, Japanese, Korean scriptsScan receipts, notes
Image labelingGeneral labels (food, plant, dogโ€ฆ)Auto-tag photos
Object detectionLocate and track objectsVisual product search
Barcode scanning1D/2D codesQR payments, inventory
Face detection, pose, segmentationLandmarks, body pose, backgroundFilters, fitness
Language IDDetect text languageRoute to translation
TranslationOffline translation between many languagesTranslate chat messages
Entity extractionAddresses, dates, phone numbers, moneySmart actions in messages
GenAI Image Description (beta)Short descriptions via Gemini NanoAlt text. See Image Description.

Some models are bundled with the app (bigger APK, available immediately); others are downloaded via Google Play services (smaller APK, needs a download first). Each API page lists the options.

A camera pipeline

CameraX to ML Kit pipeline CameraX ImageAnalysis provides frames; the MlKitAnalyzer runs a detector such as text recognition on each frame; results map to UI state in a ViewModel; the Compose UI draws overlays or shows extracted text. CameraXframes MlKitAnalyzerdetector ViewModelUI state Compose UI
Process frames continuously, but throttle state updates for a smooth UI.

Text recognition from a photo

TextScanner.ktKotlin
class TextScanner : AutoCloseable {
    private val recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)

    suspend fun scan(context: Context, uri: Uri): String {
        val image = InputImage.fromFilePath(context, uri)
        return recognizer.process(image).await().text     // kotlinx-coroutines-play-services await()
    }

    override fun close() = recognizer.close()
}

Live analysis with CameraX

Live text recognitionKotlin
val recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)

cameraController.setImageAnalysisAnalyzer(
    ContextCompat.getMainExecutor(context),
    MlKitAnalyzer(
        listOf(recognizer),
        ImageAnalysis.COORDINATE_SYSTEM_VIEW_REFERENCED,
        ContextCompat.getMainExecutor(context),
    ) { result ->
        result.getValue(recognizer)?.let { text -> viewModel.onTextDetected(text.text) }
    },
)

Language: ID, translation, entities

Translate and extract entitiesKotlin
suspend fun translateToEnglish(text: String): String {
    val lang = LanguageIdentification.getClient().identifyLanguage(text).await()
    if (lang == "und" || lang == "en") return text
    val sourceLang = TranslateLanguage.fromLanguageTag(lang) ?: return text
    val translator = Translation.getClient(
        TranslatorOptions.Builder()
            .setSourceLanguage(sourceLang)
            .setTargetLanguage(TranslateLanguage.ENGLISH)
            .build()
    )
    return translator.use {
        it.downloadModelIfNeeded(DownloadConditions.Builder().requireWifi().build()).await()
        it.translate(text).await()
    }
}

suspend fun findEntities(text: String): List<String> {
    val extractor = EntityExtraction.getClient(
        EntityExtractorOptions.Builder(EntityExtractorOptions.ENGLISH).build()
    )
    return extractor.use {
        it.downloadModelIfNeeded().await()
        it.annotate(text).await().flatMap { a -> a.entities.map { e -> "${e.type}: ${text.substring(a.start, a.end)}" } }
    }
}

Best practices

  • Close detectors when done, and reuse clients during a session.
  • Downscale large images before processing to save time and memory.
  • Use confidence thresholds, and let users correct results.
  • Download language models over Wi-Fi with user-visible progress.

Frequently asked questions

Does ML Kit send images to Google?

The on-device APIs process data locally. Review each API's documentation and your Play Data safety disclosures.

How accurate is on-device translation?

It's good for getting the gist, but less fluent than cloud translation. Label it as automatic translation.

Conclusion

ML Kit gives you OCR, labeling, detection, translation and entity extraction on device: fast, private and free. Combine it with CameraX for live features, and add an LLM only when you need open-ended generation.

Next step: make AI features work across devices and offline with Offline AI Features and Device Compatibility.

Official references

๐Ÿ“ฑ Apps built by Yunok Tech

Real Android apps on Google Play, free to download.

See all our apps โ†’

Ready to build real Android applications?

Every AI feature still runs inside an Android app that has to be fast, reliable and well structured. Strengthen the Kotlin, Jetpack Compose and architecture skills that AI integrations depend on, then apply these AI concepts with confidence.

Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.

Explore the Android course and take your next step as an Android developer.

Share: LinkedIn X / Twitter WhatsApp