# AppFunctionManager

Artifact: [androidx.appfunctions:appfunctions](https://developer.android.com/jetpack/androidx/releases/appfunctions) [View Source](https://cs.android.com/search?q=file:androidx/appfunctions/AppFunctionManager.kt+class:androidx.appfunctions.AppFunctionManager) Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

*** ** * ** ***


```
class AppFunctionManager
```

<br />

*** ** * ** ***

Provides access to interact with App Functions. This is a backward-compatible wrapper for the platform class `https://developer.android.com/reference/android/app/appfunctions/AppFunctionManager.html`.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#APP_FUNCTION_STATE_DEFAULT()` The default state of the app function. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#APP_FUNCTION_STATE_DISABLED()` The app function is disabled. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#APP_FUNCTION_STATE_ENABLED()` The app function is enabled. |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager?` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getInstance(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Gets an instance of `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager` if the AppFunction feature is supported. |

| ### Public functions |
|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/appfunctions/ExecuteAppFunctionResponse` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true) https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#executeAppFunction(androidx.appfunctions.ExecuteAppFunctionRequest)(request: https://developer.android.com/reference/kotlin/androidx/appfunctions/ExecuteAppFunctionRequest)` Execute the app function. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionActivityState>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) @https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(anyOf = ["android.permission.EXECUTE_APP_FUNCTIONS", "android.permission.DISCOVER_APP_FUNCTIONS", "android.permission.EXECUTE_APP_FUNCTIONS_SYSTEM"], conditional = true) https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getAppFunctionActivityStates(kotlin.collections.Set)(activityIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId.html>)` Retrieves the registered app functions for the specified activities. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionState>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(anyOf = ["android.permission.EXECUTE_APP_FUNCTIONS", "android.permission.DISCOVER_APP_FUNCTIONS", "android.permission.EXECUTE_APP_FUNCTIONS_SYSTEM"], conditional = true) https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getAppFunctionStates(kotlin.collections.List)(appFunctionNames: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionName>)` Retrieves the runtime state of the specified app functions. |
| `inline https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter<T>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) @https://developer.android.com/reference/kotlin/androidx/appfunctions/ExperimentalAppFunctionsApi <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter()()` Returns a `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter` for an interface annotated with `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSignature`. |
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter<T>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) @https://developer.android.com/reference/kotlin/androidx/appfunctions/ExperimentalAppFunctionsApi <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter(java.lang.Class)(interfaceClass: https://developer.android.com/reference/java/lang/Class.html<T>)` Returns a `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter` for an interface annotated with `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSignature`. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-nothing/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) @https://developer.android.com/reference/kotlin/androidx/appfunctions/ExperimentalAppFunctionsApi https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#handleAppFunction(androidx.appfunctions.HandleAppFunctionRequest)(request: https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequest)` Registers a runtime implementation of an app function bound to the calling coroutine's lifecycle. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-nothing/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) @https://developer.android.com/reference/kotlin/androidx/appfunctions/ExperimentalAppFunctionsApi https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#handleAppFunction(kotlin.String,androidx.appfunctions.SuspendingAppFunction)( functionIdentifier: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, appFunction: https://developer.android.com/reference/kotlin/androidx/appfunctions/SuspendingAppFunction )` Registers a runtime implementation of an app function bound to the calling coroutine's lifecycle. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-nothing/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) @https://developer.android.com/reference/kotlin/androidx/appfunctions/ExperimentalAppFunctionsApi https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#handleAppFunctions(kotlin.collections.List)(requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequest>)` Registers multiple runtime implementations of app functions bound to the calling coroutine's lifecycle. |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionsChangeEvent>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(anyOf = ["android.permission.EXECUTE_APP_FUNCTIONS", "android.permission.DISCOVER_APP_FUNCTIONS", "android.permission.EXECUTE_APP_FUNCTIONS_SYSTEM"], conditional = true) https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#observeAppFunctions()()` Observes changes to app functions within packages the caller can query. |
| `https://developer.android.com/reference/android/app/appfunctions/AppFunctionRegistration.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) @https://developer.android.com/reference/kotlin/androidx/appfunctions/ExperimentalAppFunctionsApi https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)( functionIdentifier: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, appFunction: https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunction )` Registers a runtime implementation for an app function, that can be executed using `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#executeAppFunction(androidx.appfunctions.ExecuteAppFunctionRequest)`. |
| `https://developer.android.com/reference/android/app/appfunctions/AppFunctionRegistration.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) @https://developer.android.com/reference/kotlin/androidx/appfunctions/ExperimentalAppFunctionsApi https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunctions(kotlin.collections.List)(requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/RegisterAppFunctionRequest>)` Registers several `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunction` implementations at once, sharing a single lifecycle. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(anyOf = ["android.permission.EXECUTE_APP_FUNCTIONS", "android.permission.DISCOVER_APP_FUNCTIONS", "android.permission.EXECUTE_APP_FUNCTIONS_SYSTEM"], conditional = true) https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)(searchSpec: https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSearchSpec)` Searches app function `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata`s. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)(functionId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, newEnabledState: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` to an app function `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` owned by the calling package. |

## Constants

### APP_FUNCTION_STATE_DEFAULT

```
const val APP_FUNCTION_STATE_DEFAULT: Int
```

The default state of the app function. Call `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` with this to reset enabled state to the default value.

### APP_FUNCTION_STATE_DISABLED

```
const val APP_FUNCTION_STATE_DISABLED: Int
```

The app function is disabled. To disable an app function, call `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` with this value.

### APP_FUNCTION_STATE_ENABLED

```
const val APP_FUNCTION_STATE_ENABLED: Int
```

The app function is enabled. To enable an app function, call `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` with this value.

## Public companion functions

### getInstance

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
fun getInstance(context: Context): AppFunctionManager?
```

Gets an instance of `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager` if the AppFunction feature is supported.

The AppFunction feature is supported if the calling user is not a profile and either of the following conditions is met:

- SDK version is 36 or higher.

- SDK version is 34 or higher, and the device implements the App Function extension ibrary.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager?` | an instance of `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager` if the AppFunction feature is supported or `null`. |

## Public functions

### executeAppFunction

```
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
suspend fun executeAppFunction(request: ExecuteAppFunctionRequest): ExecuteAppFunctionResponse
```

Execute the app function.

This method matches the platform behavior defined in `https://developer.android.com/reference/android/app/appfunctions/AppFunctionManager.html#executeAppFunction(android.app.appfunctions.ExecuteAppFunctionRequest, java.util.concurrent.Executor, android.os.CancellationSignal, android.os.OutcomeReceiver&lt;android.app.appfunctions.ExecuteAppFunctionResponse,android.app.appfunctions.AppFunctionException&gt;)`.

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/appfunctions/ExecuteAppFunctionRequest` | the app function details and the arguments. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/ExecuteAppFunctionResponse` | the result of the attempt to execute the function. |

### getAppFunctionActivityStates

```
@RequiresApi(value = 37)
@RequiresPermission(anyOf = ["android.permission.EXECUTE_APP_FUNCTIONS", "android.permission.DISCOVER_APP_FUNCTIONS", "android.permission.EXECUTE_APP_FUNCTIONS_SYSTEM"], conditional = true)
suspend fun getAppFunctionActivityStates(activityIds: Set<AppFunctionActivityId>): List<AppFunctionActivityState>
```

Retrieves the registered app functions for the specified activities.

Each `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionActivityState` contains the set of registered `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionName`s associated with a requested `https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId.html`.

Functions that do not exist or are not visible to the calling application will be silently omitted from the result. Requested activities that have no registered functions will be omitted from the result.

See `https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId.html` for potential usages, including conversion from `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ActivityId.html`.

This method follows the same permission rules as `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)`.

See `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getAppFunctionStates(kotlin.collections.List)` for retrieving the runtime state of app functions based on their names.

See `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)` on how to retrieve the `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata` of app functions.

See `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#observeAppFunctions()` for observing changes to app functions' `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata` and `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionState`s.

| Parameters |
|---|---|
| `activityIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId.html>` | The set of activity IDs to retrieve function states for. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionActivityState>` | the `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionActivityState`s of the given `https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId.html`s. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.html#getAppFunctionActivityId(android.service.voice.VoiceInteractionSession.ActivityId)` |   |

### getAppFunctionStates

```
@RequiresPermission(anyOf = ["android.permission.EXECUTE_APP_FUNCTIONS", "android.permission.DISCOVER_APP_FUNCTIONS", "android.permission.EXECUTE_APP_FUNCTIONS_SYSTEM"], conditional = true)
suspend fun getAppFunctionStates(appFunctionNames: List<AppFunctionName>): List<AppFunctionState>
```

Retrieves the runtime state of the specified app functions.

This includes runtime-changing properties such as whether the functions are currently enabled or disabled. Functions that do not exist or are not visible to the calling application will be silently omitted from the result list.

This method follows the same permission rules as `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)`.

See `https://developer.android.com/reference/android/app/appfunctions/AppFunctionManager.html#getAppFunctionActivityStates(java.util.Set&lt;android.app.appfunctions.AppFunctionActivityId&gt;, java.util.concurrent.Executor, android.os.OutcomeReceiver&lt;java.util.List&lt;android.app.appfunctions.AppFunctionActivityState&gt;,java.lang.Exception&gt;)` for retrieving the states of app functions associated with a specific activity.

See `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)` on how to retrieve the `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata` of app functions.

See `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#observeAppFunctions()` for observing changes to app functions' `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata` and `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionState`s.

| Parameters |
|---|---|
| `appFunctionNames: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionName>` | The names of the app functions to request the state for. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionState>` | the `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionState`s of the specified app functions. |

### getHandleAppFunctionRequestAdapter

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
inline fun <T : Any> getHandleAppFunctionRequestAdapter(): HandleAppFunctionRequestAdapter<T>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter` for an interface annotated with `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSignature`.

Retrieves a generated `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter` that bridges `https://developer.android.com/reference/kotlin/androidx/appfunctions/ExecuteAppFunctionRequest` and `https://developer.android.com/reference/kotlin/androidx/appfunctions/ExecuteAppFunctionResponse` with the strongly-typed signature of the interface `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter()`. Because the method uses reflection under the hood to instantiate the adapter, we recommend loading it in advance to avoid runtime latency.

This adapter allows wrapping a concrete implementation of the interface into a `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequest`. The resulting request can then be registered using `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#handleAppFunction(kotlin.String,androidx.appfunctions.SuspendingAppFunction)` or `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#handleAppFunctions(kotlin.collections.List)`.

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>` | The interface annotated with `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSignature`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter<T>` | The `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter` for the interface `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter()`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the adapter class for `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter()` cannot be found or instantiated. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter()` | (Class) |

### getHandleAppFunctionRequestAdapter

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
fun <T : Any> getHandleAppFunctionRequestAdapter(interfaceClass: Class<T>): HandleAppFunctionRequestAdapter<T>
```

Returns a `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter` for an interface annotated with `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSignature`.

Retrieves a generated `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter` that bridges `https://developer.android.com/reference/kotlin/androidx/appfunctions/ExecuteAppFunctionRequest` and `https://developer.android.com/reference/kotlin/androidx/appfunctions/ExecuteAppFunctionResponse` with the strongly-typed signature of the passed interface. Because the method uses reflection under the hood to instantiate the adapter, we recommend loading it in advance to avoid runtime latency.

This adapter allows wrapping a concrete implementation of the passed interface into a `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequest`. The resulting request can then be registered using `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#handleAppFunction(kotlin.String,androidx.appfunctions.SuspendingAppFunction)` or `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#handleAppFunctions(kotlin.collections.List)`.

| Parameters |
|---|---|
| `interfaceClass: https://developer.android.com/reference/java/lang/Class.html<T>` | The interface class annotated with `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSignature`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter<T>` | The `https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequestAdapter` for the `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter(java.lang.Class)`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the adapter class for `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter(java.lang.Class)` cannot be found or instantiated. |

### handleAppFunction

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
suspend fun handleAppFunction(request: HandleAppFunctionRequest): Nothing
```

Registers a runtime implementation of an app function bound to the calling coroutine's lifecycle.

This method suspends and keeps the function registered until the calling coroutine scope is cancelled. Under the hood, it delegates the registration to `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)` and ensures it is unregistered when the coroutine is cancelled.

For a callback-based API that does not require a coroutine scope, see `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)`.

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequest` | The request containing the function identifier and implementation. |

### handleAppFunction

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
suspend fun handleAppFunction(
    functionIdentifier: String,
    appFunction: SuspendingAppFunction
): Nothing
```

Registers a runtime implementation of an app function bound to the calling coroutine's lifecycle.

This method suspends and keeps the function registered until the calling coroutine scope is cancelled. Under the hood, it delegates the registration to `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)` and ensures it is unregistered when the coroutine is cancelled.

For a callback-based API that does not require a coroutine scope, see `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)`.

| Parameters |
|---|---|
| `functionIdentifier: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The unique identifier of the app function. |
| `appFunction: https://developer.android.com/reference/kotlin/androidx/appfunctions/SuspendingAppFunction` | The implementation of the app function to handle execution requests. |

### handleAppFunctions

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
suspend fun handleAppFunctions(requests: List<HandleAppFunctionRequest>): Nothing
```

Registers multiple runtime implementations of app functions bound to the calling coroutine's lifecycle.

This method suspends and keeps the functions registered until the calling coroutine scope is cancelled. Under the hood, it delegates the registration to `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunctions(kotlin.collections.List)` and ensures they are unregistered when the coroutine is cancelled.

For a callback-based API that does not require a coroutine scope, see `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunctions(kotlin.collections.List)`.

| Parameters |
|---|---|
| `requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/HandleAppFunctionRequest>` | The list of requests containing the function identifiers and implementations. |

### observeAppFunctions

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
@RequiresPermission(anyOf = ["android.permission.EXECUTE_APP_FUNCTIONS", "android.permission.DISCOVER_APP_FUNCTIONS", "android.permission.EXECUTE_APP_FUNCTIONS_SYSTEM"], conditional = true)
fun observeAppFunctions(): Flow<AppFunctionsChangeEvent>
```

Observes changes to app functions within packages the caller can query.

The returned flow only emits changes that occur after collection starts. Any changes before collection are not reported.

An example usage flow is:

1. Start collecting from the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` to monitor app function changes.

2. Call `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)` and `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getAppFunctionStates(kotlin.collections.List)` to get the initial list of app functions and their states.

3. When receiving `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionsChangeEvent.MetadataChanged`, call `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)` with a `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSearchSpec` that matches the changed packages to get the updated metadata.

4. When receiving `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionsChangeEvent.StatesChanged`, call `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getAppFunctionStates(kotlin.collections.List)` with the list of `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionName`s matching the changed functions to get the updated states. Note that this is guaranteed to trigger after `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionsChangeEvent.MetadataChanged` for new functions or functions that also changed states. There is no need to call `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#getAppFunctionStates(kotlin.collections.List)` when receiving `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionsChangeEvent.MetadataChanged`.

| Returns |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionsChangeEvent>` | a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` emitting `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionsChangeEvent`s representing metadata or state changes |

### registerAppFunction

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
fun registerAppFunction(
    functionIdentifier: String,
    executor: Executor,
    appFunction: AppFunction
): AppFunctionRegistration
```

Registers a runtime implementation for an app function, that can be executed using `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#executeAppFunction(androidx.appfunctions.ExecuteAppFunctionRequest)`.

`https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#executeAppFunction(androidx.appfunctions.ExecuteAppFunctionRequest)` targeting an app function provided by this method will trigger the `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunction#onExecuteAppFunction(androidx.appfunctions.ExecuteAppFunctionRequest,android.os.CancellationSignal,java.util.function.Consumer)` method of the provided implementation, as long as the process registering it is not frozen, and the `https://developer.android.com/reference/android/content/Context.html` registering it is not destroyed (at which point the registration will be removed).

You must declare the app function in your `AndroidManifest.xml` using an application-level `<property>` named `android.app.appfunctions`. See `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata` for details on the XML schema (`your_app_functions.xml` in the example below).

**Example manifest declaration:**

```kotlin
<application ...>
  <property
      android:name="android.app.appfunctions"
      android:value="your_app_functions.xml" />
  ...
</application>
```

Function implementations can only be registered from `https://developer.android.com/reference/android/app/Activity.html` or `https://developer.android.com/reference/android/app/Service.html` contexts. If registering from an `https://developer.android.com/reference/android/app/Activity.html`, strongly consider `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata#SCOPE_ACTIVITY()` for your function definition.

The `functionIdentifier` must correspond to an app function declared in your app's application-level XML assets. If the identifier is not found, this method will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`. Attempting to register a duplicate function based on the rules of `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata#scope()` will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`.

To register multiple functions at once, consider using `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunctions(kotlin.collections.List)` as a more efficient alternative.

The system holds a strong reference to the provided `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunction` implementation as long as it is registered. To prevent memory leaks and ensure the system is aware that the function is no longer available, you must explicitly call `https://developer.android.com/reference/android/app/appfunctions/AppFunctionRegistration.html#unregister()` when the function is no longer relevant (e.g., in `https://developer.android.com/reference/android/app/Activity.html#onStop()` or before `https://developer.android.com/reference/android/app/Service.html#stopForeground(boolean)`).

| Parameters |
|---|---|
| `functionIdentifier: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The unique identifier for the function, which must match an entry in the app's XML resource declarations. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the function will be invoked and the incoming `https://developer.android.com/reference/kotlin/androidx/appfunctions/ExecuteAppFunctionRequest` will be validated (verifying that the incoming platform request aligns with the declared `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata`). |
| `appFunction: https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunction` | The `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunction` implementation to be executed when the function is triggered. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/app/appfunctions/AppFunctionRegistration.html` | A `https://developer.android.com/reference/android/app/appfunctions/AppFunctionRegistration.html` object that can be used to unregister the function. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if a duplicate function is already registered (see `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata#scope()`) for the same scope, or if not called from `https://developer.android.com/reference/android/app/Activity.html` or `https://developer.android.com/reference/android/app/Service.html` contexts. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the provided `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)` is not declared in the app's application-level XML resources or if an activity-scoped function is registered from a non-Activity context. |

### registerAppFunctions

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
fun registerAppFunctions(requests: List<RegisterAppFunctionRequest>): AppFunctionRegistration
```

Registers several `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunction` implementations at once, sharing a single lifecycle.

This is a more efficient alternative to calling `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)` multiple times.

### Behavior and Lifecycle

Each function registered through this method follows the same execution and lifecycle rules as those registered with `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)`.

### Batch Operation and Atomicity

The registration is atomic: either all functions in the provided list are registered successfully, or none are. If any function in the list fails validation (e.g., it is already registered or not declared in the manifest), this method will throw an exception, and no functions from the batch will be registered. Each function in the request follows the scoping rules declared in the app's XML resources.

A single `https://developer.android.com/reference/android/app/appfunctions/AppFunctionRegistration.html` object is returned, which can be used to unregister the entire batch of functions with one call.

| Parameters |
|---|---|
| `requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/RegisterAppFunctionRequest>` | A list of `https://developer.android.com/reference/kotlin/androidx/appfunctions/RegisterAppFunctionRequest` objects, each specifying a function to be registered. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/app/appfunctions/AppFunctionRegistration.html` | A single `https://developer.android.com/reference/android/app/appfunctions/AppFunctionRegistration.html` object that can be used to unregister all the functions in the batch with one call. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if any function in the `requests` list is already registered by this app. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if any `https://developer.android.com/reference/kotlin/androidx/appfunctions/RegisterAppFunctionRequest#functionIdentifier()` is not declared in the app's application-level XML assets or the `requests` list is empty. |

### searchAppFunctions

```
@RequiresPermission(anyOf = ["android.permission.EXECUTE_APP_FUNCTIONS", "android.permission.DISCOVER_APP_FUNCTIONS", "android.permission.EXECUTE_APP_FUNCTIONS_SYSTEM"], conditional = true)
suspend fun searchAppFunctions(searchSpec: AppFunctionSearchSpec): List<AppFunctionMetadata>
```

Searches app function `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionMetadata`s.

Note that the state is not guaranteed to be the latest, as metadata can change between request and execute times when apps are updated.

The calling app can search for:

- Functions in its own package (no permission required).

- Functions in other packages that it is allowed to query via `https://developer.android.com/reference/android/content/pm/PackageManager.html#canPackageQuery(java.lang.String, java.lang.String)` when holding the `https://developer.android.com/reference/android/Manifest.permission.html#EXECUTE_APP_FUNCTIONS` permission.

- Functions in other packages that it is allowed to query via `https://developer.android.com/reference/android/content/pm/PackageManager.html#canPackageQuery(java.lang.String, java.lang.String)` when holding either the `android.Manifest.permission.EXECUTE_APP_FUNCTIONS_SYSTEM` or `android.Manifest.permission.DISCOVER_APP_FUNCTIONS` permission on `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#CINNAMON_BUN` and above.

| Parameters |
|---|---|
| `searchSpec: https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSearchSpec` | The spec of app functions to search for. |

### setAppFunctionEnabled

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
suspend fun setAppFunctionEnabled(functionId: String, newEnabledState: Int): Unit
```

Sets `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` to an app function `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` owned by the calling package.

This method matches the platform behavior defined in `https://developer.android.com/reference/android/app/appfunctions/AppFunctionManager.html#setAppFunctionEnabled(java.lang.String, int, java.util.concurrent.Executor, android.os.OutcomeReceiver&lt;java.lang.Void,java.lang.Exception&gt;)`.

| Parameters |
|---|---|
| `functionId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The identifier of the app function. |
| `newEnabledState: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The new state of the app function. Value is one of the following: - `0` - `1` - `2` <br /> |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` is not available. |