# 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)

*** ** * ** ***


```
public final 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 |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#APP_FUNCTION_STATE_DEFAULT()` The default state of the app function. |
| `static final int` | `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#APP_FUNCTION_STATE_DISABLED()` The app function is disabled. |
| `static final int` | `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#APP_FUNCTION_STATE_ENABLED()` The app function is enabled. |

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

## Constants

### APP_FUNCTION_STATE_DEFAULT

```
public static final int APP_FUNCTION_STATE_DEFAULT
```

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

### APP_FUNCTION_STATE_DISABLED

```
public static final int APP_FUNCTION_STATE_DISABLED
```

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

### APP_FUNCTION_STATE_ENABLED

```
public static final int APP_FUNCTION_STATE_ENABLED
```

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

## Public methods

### executeAppFunction

```
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
public final @NonNull ExecuteAppFunctionResponse executeAppFunction(@NonNull ExecuteAppFunctionRequest request)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/ExecuteAppFunctionRequest request` | the app function details and the arguments. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/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)
public final @NonNull List<@NonNull AppFunctionActivityState> getAppFunctionActivityStates(
    @NonNull Set<@NonNull AppFunctionActivityId> activityIds
)
```

Retrieves the registered app functions for the specified activities.

Each `https://developer.android.com/reference/androidx/appfunctions/AppFunctionActivityState` contains the set of registered `https://developer.android.com/reference/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/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)`.

See `https://developer.android.com/reference/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/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)` on how to retrieve the `https://developer.android.com/reference/androidx/appfunctions/metadata/AppFunctionMetadata` of app functions.

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId.html> activityIds` | The set of activity IDs to retrieve function states for. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/AppFunctionActivityState>` | the `https://developer.android.com/reference/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)
public final @NonNull List<@NonNull AppFunctionState> getAppFunctionStates(
    @NonNull List<@NonNull AppFunctionName> appFunctionNames
)
```

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/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/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)` on how to retrieve the `https://developer.android.com/reference/androidx/appfunctions/metadata/AppFunctionMetadata` of app functions.

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/AppFunctionName> appFunctionNames` | The names of the app functions to request the state for. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/AppFunctionState>` | the `https://developer.android.com/reference/androidx/appfunctions/AppFunctionState`s of the specified app functions. |

### getHandleAppFunctionRequestAdapter

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
public final @NonNull HandleAppFunctionRequestAdapter<@NonNull T> <T extends Object> getHandleAppFunctionRequestAdapter()
```

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

Retrieves a generated `https://developer.android.com/reference/androidx/appfunctions/HandleAppFunctionRequestAdapter` that bridges `https://developer.android.com/reference/androidx/appfunctions/ExecuteAppFunctionRequest` and `https://developer.android.com/reference/androidx/appfunctions/ExecuteAppFunctionResponse` with the strongly-typed signature of the interface `https://developer.android.com/reference/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/androidx/appfunctions/HandleAppFunctionRequest`. The resulting request can then be registered using `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#handleAppFunction(kotlin.String,androidx.appfunctions.SuspendingAppFunction)` or `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#handleAppFunctions(kotlin.collections.List)`.

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/HandleAppFunctionRequestAdapter<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | The `https://developer.android.com/reference/androidx/appfunctions/HandleAppFunctionRequestAdapter` for the interface `https://developer.android.com/reference/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/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter()` cannot be found or instantiated. |

| See also |
|---|---|
| `https://developer.android.com/reference/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
public final @NonNull HandleAppFunctionRequestAdapter<@NonNull T> <T extends Object> getHandleAppFunctionRequestAdapter(
    @NonNull Class<@NonNull T> interfaceClass
)
```

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

Retrieves a generated `https://developer.android.com/reference/androidx/appfunctions/HandleAppFunctionRequestAdapter` that bridges `https://developer.android.com/reference/androidx/appfunctions/ExecuteAppFunctionRequest` and `https://developer.android.com/reference/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/androidx/appfunctions/HandleAppFunctionRequest`. The resulting request can then be registered using `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#handleAppFunction(kotlin.String,androidx.appfunctions.SuspendingAppFunction)` or `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#handleAppFunctions(kotlin.collections.List)`.

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/HandleAppFunctionRequestAdapter<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | The `https://developer.android.com/reference/androidx/appfunctions/HandleAppFunctionRequestAdapter` for the `https://developer.android.com/reference/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/androidx/appfunctions/AppFunctionManager#getHandleAppFunctionRequestAdapter(java.lang.Class)` cannot be found or instantiated. |

### getInstance

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

```
public static final AppFunctionManager getInstance(@NonNull Context context)
```

Gets an instance of `https://developer.android.com/reference/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/androidx/appfunctions/AppFunctionManager` | an instance of `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager` if the AppFunction feature is supported or `null`. |

### handleAppFunction

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
public final @NonNull Void handleAppFunction(@NonNull HandleAppFunctionRequest request)
```

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/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/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)`.

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

### handleAppFunction

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
public final @NonNull Void handleAppFunction(
    @NonNull String functionIdentifier,
    @NonNull SuspendingAppFunction appFunction
)
```

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/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/androidx/appfunctions/AppFunctionManager#registerAppFunction(kotlin.String,java.util.concurrent.Executor,androidx.appfunctions.AppFunction)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html functionIdentifier` | The unique identifier of the app function. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/SuspendingAppFunction appFunction` | The implementation of the app function to handle execution requests. |

### handleAppFunctions

```
@RequiresApi(value = 37)
@ExperimentalAppFunctionsApi
public final @NonNull Void handleAppFunctions(
    @NonNull List<@NonNull HandleAppFunctionRequest> requests
)
```

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/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/androidx/appfunctions/AppFunctionManager#registerAppFunctions(kotlin.collections.List)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/HandleAppFunctionRequest> requests` | 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)
public final @NonNull Flow<@NonNull AppFunctionsChangeEvent> observeAppFunctions()
```

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/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)` and `https://developer.android.com/reference/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/androidx/appfunctions/AppFunctionsChangeEvent.MetadataChanged`, call `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#searchAppFunctions(androidx.appfunctions.AppFunctionSearchSpec)` with a `https://developer.android.com/reference/androidx/appfunctions/AppFunctionSearchSpec` that matches the changed packages to get the updated metadata.

4. When receiving `https://developer.android.com/reference/androidx/appfunctions/AppFunctionsChangeEvent.StatesChanged`, call `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#getAppFunctionStates(kotlin.collections.List)` with the list of `https://developer.android.com/reference/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/androidx/appfunctions/AppFunctionsChangeEvent.MetadataChanged` for new functions or functions that also changed states. There is no need to call `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#getAppFunctionStates(kotlin.collections.List)` when receiving `https://developer.android.com/reference/androidx/appfunctions/AppFunctionsChangeEvent.MetadataChanged`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/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/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
public final @NonNull AppFunctionRegistration registerAppFunction(
    @NonNull String functionIdentifier,
    @NonNull Executor executor,
    @NonNull AppFunction appFunction
)
```

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

`https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#executeAppFunction(androidx.appfunctions.ExecuteAppFunctionRequest)` targeting an app function provided by this method will trigger the `https://developer.android.com/reference/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/androidx/appfunctions/metadata/AppFunctionMetadata` for details on the XML schema (`your_app_functions.xml` in the example below).

**Example manifest declaration:**

```
<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/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/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/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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html functionIdentifier` | The unique identifier for the function, which must match an entry in the app's XML resource declarations. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | 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/androidx/appfunctions/ExecuteAppFunctionRequest` will be validated (verifying that the incoming platform request aligns with the declared `https://developer.android.com/reference/androidx/appfunctions/metadata/AppFunctionMetadata`). |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/AppFunction appFunction` | The `https://developer.android.com/reference/androidx/appfunctions/AppFunction` implementation to be executed when the function is triggered. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull 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/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/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
public final @NonNull AppFunctionRegistration registerAppFunctions(
    @NonNull List<@NonNull RegisterAppFunctionRequest> requests
)
```

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

This is a more efficient alternative to calling `https://developer.android.com/reference/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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/RegisterAppFunctionRequest> requests` | A list of `https://developer.android.com/reference/androidx/appfunctions/RegisterAppFunctionRequest` objects, each specifying a function to be registered. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull 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/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)
public final @NonNull List<@NonNull AppFunctionMetadata> searchAppFunctions(@NonNull AppFunctionSearchSpec searchSpec)
```

Searches app function `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appfunctions/AppFunctionSearchSpec searchSpec` | 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)

```
public final void setAppFunctionEnabled(@NonNull String functionId, int newEnabledState)
```

Sets `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` to an app function `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html functionId` | The identifier of the app function. |
| `int newEnabledState` | 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/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` is not available. |