AppFunctionMetadata
public final class AppFunctionMetadata
Represents an AppFunction's metadata.
The class provides the essential information to call an AppFunction. The caller has two options to invoke a function:
-
Using function schema to identify input/output: The function schema defines the input and output of a function. If
schemais not null, the caller can look up the input/output information based on the schema definition, and call the function accordingly. -
Examine
parametersandresponse: A function metadata also has parameters and response properties describe the input and output of a function. The caller can examine these fields to obtain the input/output information, and call the function accordingly.
Summary
Constants |
|
|---|---|
static final int |
A constant indicating an app function is activity-scoped. |
static final int |
A constant indicating an app function is globally-scoped. |
Public constructors |
|---|
AppFunctionMetadata( |
Public methods |
|
|---|---|
boolean |
|
final @NonNull AppFunctionComponentsMetadata |
Reusable components that could be shared within the function specification. |
final AppFunctionDeprecationMetadata |
Deprecation details about the function, if the AppFunction is deprecated. |
final @NonNull String |
A description of the AppFunction and its intended use. |
final @NonNull String |
getId()The ID used in an |
final @NonNull String |
The package name of the Android app called to execute the app function. |
final @NonNull List<@NonNull AppFunctionParameterMetadata> |
The parameters of the AppFunction. |
final @NonNull AppFunctionResponseMetadata |
The response of the AppFunction. |
final AppFunctionSchemaMetadata |
The predefined schema of the AppFunction. |
int |
hashCode() |
final boolean |
Indicates whether the function is enabled currently or not. |
@NonNull String |
toString() |
Constants
SCOPE_ACTIVITY
public static final int SCOPE_ACTIVITY
A constant indicating an app function is activity-scoped.
Multiple app function implementations with the same name can exist simultaneously, each registered from a different android.app.Activity instance, which is identified by an android.app.appfunctions.AppFunctionActivityId.
Functions with this scope must be registered by an androidx.appfunctions.AppFunctionManager that is created from an android.app.Activity context.
To execute an activity-scoped function, the caller of androidx.appfunctions.AppFunctionManager.executeAppFunction must use android.app.appfunctions.ExecuteAppFunctionRequest#setActivityId, otherwise androidx.appfunctions.AppFunctionFunctionNotFoundException will be returned.
To discover the specific activities where an activity-scoped function is currently registered, see android.app.appfunctions.AppFunctionManager.getAppFunctionStates and android.app.appfunctions.AppFunctionManager.getAppFunctionActivityStates.
The function remains registered until it is explicitly unregistered or the activity is destroyed.
IMPORTANT: Functions provided with android.app.appfunctions.AppFunctionManager.registerAppFunction called from an android.app.Activity context should prefer SCOPE_ACTIVITY. Only use SCOPE_GLOBAL for such functions if you are absolutely sure there can be only one instance of that activity.
SCOPE_GLOBAL
public static final int SCOPE_GLOBAL
A constant indicating an app function is globally-scoped.
There can be at most one app function implementation with the same name available with this scope. This is useful for functions that are tied to a singleton component, such as a foreground service.
When using android.app.appfunctions.AppFunctionManager.registerAppFunction, the function remains registered until it is explicitly unregistered or the calling context is destroyed.
To execute a globally-scoped function, the caller of androidx.appfunctions.AppFunctionManager.executeAppFunction must not use android.app.appfunctions.ExecuteAppFunctionRequest#setActivityId (or set it to null), otherwise androidx.appfunctions.AppFunctionFunctionNotFoundException will be returned.
This is always the scope for androidx.appfunctions.AppFunctionService-based functions.
IMPORTANT: Functions provided with android.app.appfunctions.AppFunctionManager.registerAppFunction called from an android.app.Activity context should prefer SCOPE_ACTIVITY. Only use SCOPE_GLOBAL for such functions if you are absolutely sure there can be only one instance of that activity.
Public constructors
AppFunctionMetadata
public AppFunctionMetadata(
@NonNull String id,
@NonNull String packageName,
boolean isEnabled,
AppFunctionSchemaMetadata schema,
@NonNull List<@NonNull AppFunctionParameterMetadata> parameters,
@NonNull AppFunctionResponseMetadata response,
@NonNull AppFunctionComponentsMetadata components,
@NonNull String description,
AppFunctionDeprecationMetadata deprecation,
@NonNull AppFunctionName name,
@NonNull AppFunctionPackageMetadata packageMetadata
)
Public methods
getComponents
public final @NonNull AppFunctionComponentsMetadata getComponents()
Reusable components that could be shared within the function specification.
getDeprecation
public final AppFunctionDeprecationMetadata getDeprecation()
Deprecation details about the function, if the AppFunction is deprecated. This will be null if the function is not deprecated.
getDescription
public final @NonNull String getDescription()
A description of the AppFunction and its intended use.
getId
public final @NonNull String getId()
The ID used in an androidx.appfunctions.ExecuteAppFunctionRequest to refer to this AppFunction.
getPackageName
public final @NonNull String getPackageName()
The package name of the Android app called to execute the app function.
getParameters
public final @NonNull List<@NonNull AppFunctionParameterMetadata> getParameters()
The parameters of the AppFunction.
getResponse
public final @NonNull AppFunctionResponseMetadata getResponse()
The response of the AppFunction.
getSchema
public final AppFunctionSchemaMetadata getSchema()
The predefined schema of the AppFunction. If null, it indicates this function is not implement a particular predefined schema.
isEnabled
public final boolean isEnabled()
Indicates whether the function is enabled currently or not.