AppFunctionService


public abstract class AppFunctionService
extends Service

java.lang.Object
   ↳ 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>
 
 

See also:

Summary

Constants

String SERVICE_INTERFACE

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

Inherited constants

Public constructors

AppFunctionService()

Public methods

final IBinder onBind(Intent intent)

Return the communication channel to the service.

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

Called by the system to execute a specific app function.

Inherited methods

Constants

SERVICE_INTERFACE

public static final String SERVICE_INTERFACE

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

Constant Value: "android.app.appfunctions.AppFunctionService"

Public constructors

AppFunctionService

public AppFunctionService ()

Public methods

onBind

public final IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned 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.

Returns
IBinder This value cannot be null.

onExecuteFunction

public abstract void onExecuteFunction (ExecuteAppFunctionRequest request, 
                String callingPackage, 
                CancellationSignal cancellationSignal, 
                Consumer<ExecuteAppFunctionResponse> callback)

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 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: A callback to report back the result. This value cannot be null.