AppFunctionService


abstract class AppFunctionService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.app.appfunctions.AppFunctionService

Abstract base class to provide app functions to the system.

Include the following in the manifest:

<service android:name=".YourService"
        android:permission="android.permission.BIND_APP_FUNCTION_SERVICE">
     <intent-filter>
       <action android:name="android.app.appfunctions.AppFunctionService" />
     </intent-filter>
  </service>
  
  

Summary

Constants
static String

The Intent that must be declared as handled by the service.

Inherited constants
Public constructors

Public methods
IBinder
onBind(intent: Intent?)

Return the communication channel to the service.

abstract Unit
onExecuteFunction(request: ExecuteAppFunctionRequest, callingPackage: String, cancellationSignal: CancellationSignal, callback: Consumer<ExecuteAppFunctionResponse!>)

Called by the system to execute a specific app function.

Inherited functions

Constants

SERVICE_INTERFACE

static val SERVICE_INTERFACE: String

The Intent that must be declared as handled by the service. To be supported, the service must also require the BIND_APP_FUNCTION_SERVICE permission so that other applications can not abuse it.

Value: "android.app.appfunctions.AppFunctionService"

Public constructors

AppFunctionService

AppFunctionService()

Public methods

onBind

fun onBind(intent: Intent?): IBinder

Return the communication channel to the service. May return null if clients can not bind to the service. The returned android.os.IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent Intent?: This value may be null.
Return
IBinder This value cannot be null.

onExecuteFunction

abstract fun onExecuteFunction(
    request: ExecuteAppFunctionRequest,
    callingPackage: String,
    cancellationSignal: CancellationSignal,
    callback: Consumer<ExecuteAppFunctionResponse!>
): Unit

Called by the system to execute a specific app function.

This method is triggered when the system requests your AppFunctionService to handle a particular function you have registered and made available.

To ensure proper routing of function requests, assign a unique identifier to each function. This identifier doesn't need to be globally unique, but it must be unique within your app. For example, a function to order food could be identified as "orderFood". In most cases this identifier should come from the ID automatically generated by the AppFunctions SDK. You can determine the specific function to invoke by calling android.app.appfunctions.ExecuteAppFunctionRequest#getFunctionIdentifier().

This method is always triggered in the main thread. You should run heavy tasks on a worker thread and dispatch the result with the given callback. You should always report back the result using the callback, no matter if the execution was successful or not.

This method also accepts a CancellationSignal that the app should listen to cancel the execution of function if requested by the system.
This method must be called from the main thread of your app.

Parameters
request ExecuteAppFunctionRequest: The function execution request. This value cannot be null.
callingPackage String: The package name of the app that is requesting the execution. This value cannot be null.
cancellationSignal CancellationSignal: A signal to cancel the execution. This value cannot be null.
callback Consumer<ExecuteAppFunctionResponse!>: A callback to report back the result. This value cannot be null.