AppFunctionManagerCompat


public final 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

static final int

The default state of the app function.

static final int

The app function is disabled.

static final int

The app function is enabled.

Public methods

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

Execute the app function.

static final AppFunctionManagerCompat

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

final boolean

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

final boolean
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
isAppFunctionEnabled(
    @NonNull String packageName,
    @NonNull String functionId
)

Checks if functionId in packageName is enabled.

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

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

final void
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true)
setAppFunctionEnabled(@NonNull String functionId, int newEnabledState)

Sets newEnabledState to an app function functionId 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 setAppFunctionEnabled 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 setAppFunctionEnabled 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 setAppFunctionEnabled 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 android.app.appfunctions.AppFunctionManager.executeAppFunction.

Parameters
@NonNull ExecuteAppFunctionRequest request

the app function details and the arguments.

Returns
@NonNull ExecuteAppFunctionResponse

the result of the attempt to execute the function.

getInstance

Added in 1.0.0-alpha01
public static final AppFunctionManagerCompat getInstance(@NonNull Context context)

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.

isAppFunctionEnabled

public final boolean isAppFunctionEnabled(@NonNull String functionId)

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

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

Parameters
@NonNull String functionId

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)
public final boolean isAppFunctionEnabled(
    @NonNull String packageName,
    @NonNull String functionId
)

Checks if functionId in packageName is enabled.

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

Parameters
@NonNull String packageName

The package name of the owner of functionId.

@NonNull String functionId

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)
public final @NonNull Flow<@NonNull List<@NonNull AppFunctionMetadata>> observeAppFunctions(@NonNull AppFunctionSearchSpec searchSpec)

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
@NonNull AppFunctionSearchSpec searchSpec

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

Returns
@NonNull Flow<@NonNull List<@NonNull 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)
public final void setAppFunctionEnabled(@NonNull String functionId, int newEnabledState)

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
@NonNull String functionId

The identifier of the app function.

int newEnabledState

The new state of the app function.

Throws
kotlin.IllegalArgumentException

If the functionId is not available.