AppFunctionManagerCompat


class AppFunctionManagerCompat


Provides access to interact with App Functions. This is a backward-compatible wrapper for the platform class android.app.appfunctions.AppFunctionManager.

Summary

Constants

const Int

The default state of the app function.

const Int

The app function is disabled.

const Int

The app function is enabled.

Public companion functions

AppFunctionManagerCompat?
getInstance(context: Context)

Gets an instance of AppFunctionManagerCompat if the AppFunction feature is supported.

Public functions

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

Execute the app function.

suspend Boolean

Checks if functionId in the caller's package is enabled.

suspend Boolean
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
isAppFunctionEnabled(packageName: String, functionId: String)

Checks if functionId in packageName is enabled.

Flow<List<AppFunctionMetadata>>
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
observeAppFunctions(searchSpec: AppFunctionSearchSpec)

Observes for available app functions metadata based on the provided filters.

suspend Unit
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
setAppFunctionEnabled(functionId: String, newEnabledState: Int)

Sets newEnabledState to an app function functionId owned by the calling package.

Constants

APP_FUNCTION_STATE_DEFAULT

const val APP_FUNCTION_STATE_DEFAULTInt

The default state of the app function. Call setAppFunctionEnabled with this to reset enabled state to the default value.

APP_FUNCTION_STATE_DISABLED

const val APP_FUNCTION_STATE_DISABLEDInt

The app function is disabled. To disable an app function, call setAppFunctionEnabled with this value.

APP_FUNCTION_STATE_ENABLED

const val APP_FUNCTION_STATE_ENABLEDInt

The app function is enabled. To enable an app function, call setAppFunctionEnabled with this value.

Public companion functions

getInstance

Added in 1.0.0-alpha01
fun getInstance(context: Context): AppFunctionManagerCompat?

Gets an instance of AppFunctionManagerCompat if the AppFunction feature is supported.

Support is determined by verifying the SDK version is at least 33 and if the device implements the App Functions extension library.

Returns
AppFunctionManagerCompat?

an instance of AppFunctionManagerCompat 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 android.app.appfunctions.AppFunctionManager.executeAppFunction.

Parameters
request: ExecuteAppFunctionRequest

the app function details and the arguments.

Returns
ExecuteAppFunctionResponse

the result of the attempt to execute the function.

isAppFunctionEnabled

suspend fun isAppFunctionEnabled(functionId: String): Boolean

Checks if functionId in the caller's package is enabled.

This method matches the platform behavior defined in android.app.appfunctions.AppFunctionManager.isAppFunctionEnabled.

Parameters
functionId: String

The identifier of the app function.

Throws
kotlin.IllegalArgumentException

If the functionId is not available in caller's package.

isAppFunctionEnabled

@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
suspend fun isAppFunctionEnabled(packageName: String, functionId: String): Boolean

Checks if functionId in packageName is enabled.

This method matches the platform behavior defined in android.app.appfunctions.AppFunctionManager.isAppFunctionEnabled.

Parameters
packageName: String

The package name of the owner of functionId.

functionId: String

The identifier of the app function.

Throws
kotlin.IllegalArgumentException

If the functionId is not available under packageName.

observeAppFunctions

Added in 1.0.0-alpha01
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
fun observeAppFunctions(searchSpec: AppFunctionSearchSpec): Flow<List<AppFunctionMetadata>>

Observes for available app functions metadata based on the provided filters.

Allows discovering app functions that match the given searchSpec criteria and continuously emits updates when relevant metadata changes. The calling app can only observe metadata for functions in packages that it is allowed to query via android.content.pm.PackageManager.canPackageQuery. If a package is not queryable by the calling app, its functions' metadata will not be visible.

Updates to AppFunctionMetadata can occur when the app defining the function is updated or when a function's enabled state changes.

If multiple updates happen within a short duration, only the latest update might be emitted.

Parameters
searchSpec: AppFunctionSearchSpec

an AppFunctionSearchSpec instance specifying the filters for searching the app function metadata.

Returns
Flow<List<AppFunctionMetadata>>

a flow that emits a list of AppFunctionMetadata matching the search criteria and updated versions of this list when underlying data changes.

setAppFunctionEnabled

Added in 1.0.0-alpha01
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
suspend fun setAppFunctionEnabled(functionId: String, newEnabledState: Int): Unit

Sets newEnabledState to an app function functionId owned by the calling package.

This method matches the platform behavior defined in android.app.appfunctions.AppFunctionManager.setAppFunctionEnabled.

Parameters
functionId: String

The identifier of the app function.

newEnabledState: Int

The new state of the app function.

Throws
kotlin.IllegalArgumentException

If the functionId is not available.