Android 17 shifts the platform from a traditional app launcher toward an intelligence system where users ask assistants like Gemini to complete tasks across apps. Instead of brittle UI scraping or one-off intent extras, AppFunctions and the Android Model Context Protocol (MCP) let your app publish typed, discoverable tools directly to the OS.

Why AppFunctions Matter in Android 17

Historically, letting an assistant act inside your app meant maintaining XML shortcuts.xml definitions or relying on custom voice intents. AppFunctions replace that glue with Kotlin-first annotations and generated schemas:

  • Typed inputs and outputs: Arguments and return values are serialized into structured schemas rather than untyped Bundle extras.
  • On-device and MCP ready: The same function contract can be surfaced to Gemini on-device or bridged through Android MCP tooling.
  • Explicit capability boundaries: You decide which domain actions are safe to expose (e.g., creating a note, toggling a timer, querying order status).

1. Add the Jetpack AppFunctions Dependencies

In your app module's build.gradle.kts, add the AppFunctions runtime and KSP compiler so schemas are generated at build time:

kotlin
dependencies {
    implementation("androidx.appfunctions:appfunctions-runtime:1.0.0")
    ksp("androidx.appfunctions:appfunctions-compiler:1.0.0")
}

2. Declare an @AppFunction Service

Group related capabilities into a service class and annotate each exposed method with @AppFunction. Keep parameters flat, well-named, and documented—assistants rely on parameter names and KDoc descriptions to pick the right tool.

kotlin
class NotesAppFunctions(
    private val notesRepository: NotesRepository
) {
    @AppFunction
    suspend fun createQuickNote(
        appFunctionContext: AppFunctionContext,
        title: String,
        body: String,
        pinned: Boolean = false
    ): CreatedNoteResult {
        val note = notesRepository.insert(
            title = title.trim(),
            body = body.trim(),
            pinned = pinned
        )
        return CreatedNoteResult(
            noteId = note.id,
            deepLink = "myapp://notes/${note.id}"
        )
    }
}

3. Return Actionable, Safe Results

When an assistant invokes your function, return a concise result object containing an identifier and, if helpful, a deep link so the user can jump straight into the updated screen.

kotlin
@AppFunctionSerializable
data class CreatedNoteResult(
    val noteId: String,
    val deepLink: String
)

Security & Validation Checklist

  1. Validate every argument: Treat assistant-supplied strings like untrusted network input—enforce length limits and sanitize paths.
  2. Require confirmation for destructive actions: Never delete records, send payments, or post publicly without an explicit user confirmation step.
  3. Keep execution fast: Offload heavy work to WorkManager and return a pending status if the operation takes more than a couple of seconds.

4. Testing with Android MCP and Local Tooling

During development, you can inspect your generated AppFunction schema in build/generated/ksp/ and verify tool invocation using Android Studio's AppFunctions inspector or an MCP test harness before shipping to production.