๐Ÿค– Android AI and Generative AI

Using AI to Generate App Content Dynamically

AI can generate quiz questions, product descriptions, workout plans, onboarding tips or personalised summaries inside your app. Doing it well means treating model output as untrusted data: structured, validated, moderated, cached and clearly labelled.

โœ๏ธ Yunok Tech ๐Ÿ“… Updated โฑ 3 min read ๐ŸŽฏ Intermediate
On this page
  1. A safe generation pipeline
  2. Structured output instead of free text
  3. Generate on the client or the server?
  4. Moderation and policy
  5. Presenting generated content
  6. Use cases
  7. Common mistakes
  8. Frequently asked questions
  9. Conclusion

Static content doesn't adapt: the same tips for every user, the same practice questions every day. Generated content can adapt to a learner's level, a user's goals or a product's attributes. It can also be wrong, inappropriate, or inconsistent with your app's design, unless you engineer guardrails.

A safe generation pipeline

Pipeline for AI-generated app content A request with context goes to a model with a JSON schema. The output is parsed and validated against business rules, then passed through moderation. Valid content is cached and rendered with an AI label; invalid output triggers a retry or a static fallback. Requestcontext ModelJSON schema Validaterules Moderatesafety Cache + renderlabelled invalid โ†’ retry once rejected โ†’ static fallback
Model output never goes straight to the screen. It passes validation and moderation first.

Structured output instead of free text

QuizGenerator.ktKotlin
@Serializable
data class QuizQuestion(val question: String, val options: List<String>, val correctIndex: Int, val explanation: String)

@Serializable
data class Quiz(val topic: String, val questions: List<QuizQuestion>)

class QuizGenerator(private val model: GenerativeModel) {

    suspend fun generate(topic: String, level: String): Quiz? {
        val prompt = """
            Create 5 multiple-choice questions about "$topic" for a $level Android learner.
            Each question: 4 options, exactly one correct (correctIndex 0-3), a one-sentence explanation.
            Use only well-established facts; avoid version-specific numbers.
        """.trimIndent()
        repeat(2) {                                         // one retry on invalid output
            val raw = model.generateContent(prompt).text ?: return@repeat
            val quiz = runCatching { Json { ignoreUnknownKeys = true }.decodeFromString<Quiz>(raw) }.getOrNull()
            if (quiz != null && quiz.isValid()) return quiz
        }
        return null                                         // caller shows curated fallback quiz
    }
}

/** Business-rule validation the schema can't express. */
fun Quiz.isValid(): Boolean = questions.size == 5 && questions.all { q ->
    q.options.size == 4 && q.correctIndex in 0..3 &&
    q.options.distinct().size == 4 && q.question.length in 10..300
}

Configure the model with responseMimeType = "application/json" and a responseSchema (see structured output example) so it's constrained to your shape, then still validate rules such as distinct options.

Generate on the client or the server?

ContentWhereWhy
Shared by many users (product descriptions, daily tips)Server, generated once, reviewed, cachedCost, consistency, human review possible
Personalised, low-risk (practice questions for a user)Client via Firebase AI Logic, or backendPersonalisation; validate and cache per user
Sensitive domains (health, finance)Server with strict review, or don't generateAccuracy and liability

Moderation and policy

  • Use model safety settings and an additional moderation step for user-visible content.
  • Google Play's policies require apps with AI-generated content to prevent prohibited content and to provide ways for users to report offensive content. Review the current policy.
  • Avoid generating content about real people, or anything that could be mistaken for authoritative advice.

Presenting generated content

  • Label it ("Generated by AI"), and let users regenerate, report or hide it.
  • Keep a curated static fallback so the feature never shows an empty state.
  • Cache results so the same content doesn't change unexpectedly between visits.

Use cases

Learning apps

Practice questions adapted to level, validated and with explanations. See AI Study Assistant.

E-commerce

Server-generated product description drafts that merchants edit and approve.

Fitness

Workout variations from a fixed, validated exercise catalogue, with the model choosing and ordering rather than inventing exercises.

Common mistakes

  • Rendering raw model text with HTML or Markdown that can break the layout or inject links.
  • Trusting numbers, prices or facts generated by the model.
  • Generating per screen view instead of caching, which drives cost and inconsistency.
  • No reporting path for bad content.

Frequently asked questions

Can I let the model invent quiz answers?

Risky. Prefer grounding generation in your own verified content (RAG), and validate. See RAG for Android Apps.

How do I keep a consistent style?

Use a system instruction with style rules and examples, a low temperature, and a fixed schema, and evaluate samples regularly.

Do I need to disclose AI-generated content?

Labelling builds trust and may be required by platform policy or law in some contexts. Check current Play policy and local regulations.

Conclusion

Generated content is valuable when it's structured, validated, moderated, cached and labelled, with a static fallback. Generate shared content on the server, personalise carefully on the client, and never let raw model output reach users unchecked.

Next step: make your app's content findable with Build an AI-Powered Search Feature.

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