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 |
Public functions |
|
---|---|
suspend ExecuteAppFunctionResponse |
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true) Execute the app function. |
suspend Boolean |
isAppFunctionEnabled(functionId: String) Checks if |
suspend Boolean |
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true) Checks if |
Flow<List<AppFunctionMetadata>> |
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true) Observes for available app functions metadata based on the provided filters. |
suspend Unit |
@RequiresPermission(value = "android.permission.EXECUTE_APP_FUNCTIONS", conditional = true) Sets |
Constants
APP_FUNCTION_STATE_DEFAULT
const val APP_FUNCTION_STATE_DEFAULT: Int
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_DISABLED: Int
The app function is disabled. To disable an app function, call setAppFunctionEnabled
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 setAppFunctionEnabled
with this value.
Public companion functions
getInstance
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 |
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 |
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: String |
The identifier of the app function. |
Throws | |
---|---|
kotlin.IllegalArgumentException |
If the |
observeAppFunctions
@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 |
Returns | |
---|---|
Flow<List<AppFunctionMetadata>> |
a flow that emits a list of |
setAppFunctionEnabled
@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 |