AppFunctionSignature


@Retention(value = AnnotationRetention.SOURCE)
@Target(allowedTargets = [AnnotationTarget.CLASS])
public annotation AppFunctionSignature


Annotation to define an AppFunction signature that will have its implementation registered using android.app.appfunctions.AppFunctionManager.registerAppFunction.

Example

First, define your interface representing the signature:

import androidx.appfunctions.AppFunctionSignature
import
androidx.appfunctions.metadata.AppFunctionMetadata

@AppFunctionSignature(
scope = AppFunctionMetadata.SCOPE_ACTIVITY,
appFunctionXmlFileName = "cart_functions"
)
fun interface AddCurrentItemToCart {
/** Adds the item currently shown on screen to the cart. Returns the new cart size. */
suspend fun addToCart(quantity: Int): Int
}

Generated content

The AppFunction compiler processes classes marked with this annotation to generate an AppFunction XML file named after the appFunctionXmlFileName parameter. This file is placed in the application's assets directory and describes the AppFunction signatures exposed.

<appfunctions>
<appfunction>
<id>package.name.AddCurrentItemToCart#addToCart</id>
<scope>activity</scope>
<parameters>...</parameters>
<response>...</response>
</appfunction>
</appfunctions>

Then, declare the generated XML file name in your AndroidManifest.xml:

<application ...>
<property
android:name="android.app.appfunctions"
android:value="cart_functions.xml" />
...
</application>

To declare mulltiple xml files in the manifest, use comma separated values. For example:

<application ...>
<property
android:name="android.app.appfunctions"
android:value="cart_functions.xml,payments_functions.xml" />
...
</application>

Supported Types

For a detailed list of supported types and the rules governing their serialization, see androidx.appfunctions.AppFunctionSerializable.

Summary

Public constructors

AppFunctionSignature(
    int scope,
    @NonNull String appFunctionXmlFileName,
    boolean isDescribedByKDoc
)

Public methods

final @NonNull String

The name of the XML resource file containing the app function metadata definition represented by this signature.

final int

The scope of the app function.

final boolean

Whether to use the functional interface's abstract method KDoc as a function's description for the agent.

Public constructors

AppFunctionSignature

Added in 1.0.0-alpha10
public AppFunctionSignature(
    int scope,
    @NonNull String appFunctionXmlFileName,
    boolean isDescribedByKDoc
)

Public methods

getAppFunctionXmlFileName

public final @NonNull String getAppFunctionXmlFileName()

The name of the XML resource file containing the app function metadata definition represented by this signature.

Multiple signatures can specify the same XML file name to group their metadata definitions into a single XML resource file.

getScope

public final int getScope()

The scope of the app function.

The scope determines the function's lifecycle and uniqueness rules. Depending on the scope, there could be at most one or multiple functions registered in the system with the same androidx.appfunctions.metadata.AppFunctionName.

Possible values:

isDescribedByKDoc

Added in 1.0.0-alpha10
public final boolean isDescribedByKDoc()

Whether to use the functional interface's abstract method KDoc as a function's description for the agent. The default value is false.

If set to true, the KDoc will be used to populate:

Note: If an AppFunctionInstruction annotation is also present on the method, parameter, or return type, its value will take precedence and override the corresponding KDoc description.

Example:

@AppFunctionSignature(
scope = AppFunctionMetadata.SCOPE_GLOBAL,
appFunctionXmlFileName = "my_functions",
isDescribedByKDoc = true
)
fun interface EnableCaptionsSignature {
/**
* Enables closed captions for media playback.
*
* @param language The language code for the captions (e.g., "en", "es").
* @param showBackground Whether to display a dark background behind the caption text.
* @return Whether the captions were successfully enabled.
*/

suspend fun enableCaptions(language: String, showBackground: Boolean): Boolean
}

In this example: