AppFunctionServiceEntryPoint


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


Annotation to mark AppFunctionService as an entry point.

This annotation helps generate a service, bridging AppFunctionService.onExecuteFunction and AppFunction-annotated methods defined in the same class.

Example

First, define your service:

import androidx.appfunctions.AppFunctionServiceEntryPoint
import
androidx.appfunctions.AppFunction
import
androidx.appfunctions.AppFunctionService

@AppFunctionServiceEntryPoint(
serviceName = "MyAppFunctionService",
appFunctionXmlFileName = "my_service"
)
abstract class BaseMyAppFunctionService : AppFunctionService() {
@AppFunction fun add(a: Int, b: Int): Int = a + b
}

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

<service
android:name=".MyAppFunctionService"
android:permission="android.permission.BIND_APP_FUNCTION_SERVICE"
android:exported="true">
<property
android:name="android.app.appfunctions.schema"
android:value="app_functions_schema.xsd" />
<property
android:name="android.app.appfunctions.v2"
android:value="my_service.xml" />
<intent-filter>
<action android:name="android.app.appfunctions.AppFunctionService" />
</intent-filter>
</service>

Generated content

The AppFunction compiler processes classes marked with this annotation to generate two key artifacts:

  • A concrete service implementation: The compiler generates a subclass of your abstract class (BaseMyAppFunctionService in the example above) with the name specified in the serviceName parameter. In addition to the generated onExecuteFunction implementation, the function IDs that can be used with AppFunctionManager.setAppFunctionEnabled are also available in the companion object. The generated service has the following structure:

public class MyAppFunctionService : BaseMyAppFunctionService() {
override suspend fun onExecuteFunction(
request: ExecuteAppFunctionRequest
): ExecuteAppFunctionResponse {
return when (request.functionIdentifier) {
FUNCTION_ID_ADD -> {
add(request.parameters.getInt("a"), request.getParameters.getInt("b"))
}
...
}.toAppFunctionResponse()
}

public companion object {
public const val FUNCTION_ID_ADD: String = <id>
}
}
  • An AppFunction XML file: The compiler generates an XML file named after the appFunctionXmlFileName parameter. This file is placed in the application's assets directory and describes the AppFunctions exposed by this entry point.

<appfunctions>
<appfunction>
<id>add</id>
<enabledByDefault>true</enabledByDefault>
<parameters>...</parameters>
<response>...</response>
</appfunction>
</appfunctions>

Summary

Public constructors

AppFunctionServiceEntryPoint(
    @NonNull String serviceName,
    @NonNull String appFunctionXmlFileName
)

Public methods

final @NonNull String

The name of the generated app function XML file.

final @NonNull String

The name of the generated service class.

Public constructors

AppFunctionServiceEntryPoint

Added in 1.0.0-alpha10
public AppFunctionServiceEntryPoint(
    @NonNull String serviceName,
    @NonNull String appFunctionXmlFileName
)
Parameters
@NonNull String serviceName

The name of the generated service class.

@NonNull String appFunctionXmlFileName

The name of the generated app function XML file.

Public methods

getAppFunctionXmlFileName

public final @NonNull String getAppFunctionXmlFileName()

The name of the generated app function XML file.

getServiceName

public final @NonNull String getServiceName()

The name of the generated service class.