๐Ÿค– Android AI and Generative AI

ML Kit GenAI APIs Explained

ML Kit GenAI gives Android apps ready-made, on-device generative features powered by Gemini Nano: summarise, proofread, rewrite, describe images, transcribe speech and run custom prompts. This guide compares the APIs, explains their shared lifecycle, and shows Kotlin examples.

โœ๏ธ Yunok Tech ๐Ÿ“… Updated โฑ 3 min read ๐ŸŽฏ Intermediate
On this page
  1. The APIs
  2. The shared lifecycle
  3. Example: Rewriting
  4. Example: Proofreading
  5. Example: Image Description
  6. Task API or Prompt API?
  7. Constraints to design around
  8. Real-world uses
  9. Common mistakes
  10. Frequently asked questions
  11. Conclusion

Building on-device generative features used to mean bundling a model, managing GPU delegates and tuning prompts yourself. ML Kit GenAI packages common tasks as high-level APIs on top of Gemini Nano, which Android's AICore service manages. You call a client, check availability, and get results without network or per-request fees.

Status

At the time of writing, Google lists Summarization, Proofreading, Rewriting, Image Description and Prompt as beta, and Speech Recognition as alpha. Beta APIs can change and have no SLA, and device support is limited to specific models. Always check the official pages for current details.

The APIs

APIInput โ†’ outputTypical feature
SummarizationArticle or conversation โ†’ 1โ€“3 bullet points"Summarise this note/chat"
ProofreadingShort text โ†’ corrected textFix typos before sending
RewritingShort text โ†’ restyled versions (e.g. shorter, friendlier, more professional)Tone adjustment in a composer
Image DescriptionBitmap โ†’ short descriptionAlt text, accessibility
Speech RecognitionAudio โ†’ textDictation, voice notes
PromptCustom text or image prompt โ†’ generated textClassification, extraction, custom short tasks

The shared lifecycle

Common lifecycle of ML Kit GenAI clients Create a client with options, check feature status, download the feature if needed, run inference with optional streaming, and close the client when done. getClientoptions checkStatus4 states downloadif needed runInferencestream or await close()release
Learn the lifecycle once and every GenAI API feels the same. Details are in the Gemini Nano guide.

Example: Rewriting

ToneRewriter.kt (beta API, names may change)Kotlin
// implementation("com.google.mlkit:genai-rewriting:<version>")
class ToneRewriter(context: Context) : AutoCloseable {
    private val shorten = Rewriting.getClient(
        RewriterOptions.builder(context)
            .setOutputType(RewriterOptions.OutputType.SHORTEN)
            .setLanguage(RewriterOptions.Language.ENGLISH)
            .build()
    )

    suspend fun isReady(): Boolean = shorten.checkFeatureStatus().await() == FeatureStatus.AVAILABLE

    /** Returns up to a few suggestions; the user picks one. */
    suspend fun shorter(text: String): List<String> =
        shorten.runInference(RewritingRequest.builder(text).build()).await()
            .results.map { it.text }

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

Example: Proofreading

Proofreader.kt (beta API, names may change)Kotlin
// implementation("com.google.mlkit:genai-proofreading:<version>")
val proofreader = Proofreading.getClient(
    ProofreaderOptions.builder(context)
        .setInputType(ProofreaderOptions.InputType.KEYBOARD)     // typed text (vs. VOICE)
        .setLanguage(ProofreaderOptions.Language.ENGLISH)
        .build()
)
suspend fun fix(text: String): String? =
    proofreader.runInference(ProofreadingRequest.builder(text).build()).await()
        .results.firstOrNull()?.text

Example: Image Description

AltTextGenerator.kt (beta API, names may change)Kotlin
// implementation("com.google.mlkit:genai-image-description:<version>")
val describer = ImageDescription.getClient(ImageDescriberOptions.builder(context).build())

suspend fun altText(bitmap: Bitmap): String =
    describer.runInference(ImageDescriptionRequest.builder(bitmap).build()).await().description

Task API or Prompt API?

  • Task APIs (summarise, proofread, rewrite, describe) come with tuned prompts and quality evaluation by Google. Prefer them whenever your feature matches.
  • Prompt API gives flexibility for custom tasks such as classifying a message, extracting fields or generating short labels. You own prompt quality and evaluation, and outputs can vary by Gemini Nano version.

Constraints to design around

  • Device support is limited. Check status before showing UI, and provide a fallback or hide the feature.
  • Foreground only: background inference is blocked.
  • Quotas: per-app inference quota (BUSY) and battery-use quotas.
  • Input limits and languages vary per API. Summarisation, for example, documents roughly 4,000 input tokens and a small set of languages.

Real-world uses

Messaging

Proofread and rewrite in the composer. Private messages never leave the phone.

Notes and email

Summaries of long notes or threads, offered only on supported devices.

Accessibility

Auto-generated alt text drafts for user-uploaded images, editable before saving.

Common mistakes

  • Showing AI buttons without checking feature status.
  • Running inference automatically on every keystroke and hitting quotas.
  • Applying suggestions automatically without letting the user review them.
  • Forgetting close(), which leaks resources.

Frequently asked questions

Do ML Kit GenAI APIs cost money?

There's no per-request fee, because inference runs on the device. Your costs are engineering effort and the user's device resources.

Can I use them on the emulator?

Generally not, since Gemini Nano requires supported physical devices. Test on the devices listed in the documentation.

What about unsupported devices?

Hide the feature, or offer a cloud alternative with user consent. See Cloud AI vs On-Device AI.

Conclusion

ML Kit GenAI offers private, on-device generative features with a consistent lifecycle: get a client, check status, download, run inference, close. Prefer the task APIs where they fit, use the Prompt API for custom tasks, and design for limited device support, foreground-only use and quotas.

Next step: build a complete feature with these APIs in How to Build an AI Writing Assistant for Android.

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