AppFunctionService


abstract class AppFunctionService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.app.appsearch.functions.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.appsearch.functions.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

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 AppFunctionManager.PERMISSION_BIND_APP_FUNCTION_SERVICE permission so that other applications can not abuse it.

Value: "android.app.appsearch.functions.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,
    callback: Consumer<AppSearchResult<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". You can determine the specific function to invoke by calling android.app.appsearch.functions.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 must be called from the main thread of your app.

Parameters
request ExecuteAppFunctionRequest: The function execution request. This value cannot be null.
callback Consumer<AppSearchResult<ExecuteAppFunctionResponse!>!>: A callback to report back the result. This value cannot be null.