# AppFunctionServiceEntryPoint

Artifact: [androidx.appfunctions:appfunctions](https://developer.android.com/jetpack/androidx/releases/appfunctions) [View Source](https://cs.android.com/search?q=file:androidx/appfunctions/AppFunctionServiceEntryPoint.kt+class:androidx.appfunctions.AppFunctionServiceEntryPoint) Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

*** ** * ** ***


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

<br />

*** ** * ** ***

Annotation to mark `https://developer.android.com/reference/androidx/appfunctions/AppFunctionService` as an entry point.

This annotation helps generate a service, bridging `https://developer.android.com/reference/androidx/appfunctions/AppFunctionService#onExecuteFunction(android.app.appfunctions.ExecuteAppFunctionRequest,kotlin.String,android.content.pm.SigningInfo,android.os.CancellationSignal,android.os.OutcomeReceiver)` and `https://developer.android.com/reference/androidx/appfunctions/AppFunctionDeclaration`-annotated methods defined in the same class.

### Example

First, define your service:

```
import androidx.appfunctions.AppFunctionServiceEntryPoint
import androidx.appfunctions.AppFunctionDeclaration
import androidx.appfunctions.AppFunctionService

@AppFunctionServiceEntryPoint(
  serviceName = "MyAppFunctionService",
  appFunctionXmlFileName = "my_service"
)
abstract class BaseMyAppFunctionService : AppFunctionService() {
  /** Adds [a] to [b]. */
  @AppFunctionDeclaration(isDescribedByKDoc = true)
  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 `https://developer.android.com/reference/androidx/appfunctions/AppFunctionServiceEntryPoint#(kotlin.String,kotlin.String)` parameter. In addition to the generated `onExecuteFunction` implementation, the function IDs that can be used with `https://developer.android.com/reference/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` 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 `https://developer.android.com/reference/androidx/appfunctions/AppFunctionServiceEntryPoint#(kotlin.String,kotlin.String)` 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>
```

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appfunctions/AppFunctionService` |   |
| `https://developer.android.com/reference/androidx/appfunctions/AppFunctionDeclaration` |   |

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/appfunctions/AppFunctionServiceEntryPoint#getAppFunctionXmlFileName()()` The name of the generated app function XML file. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/appfunctions/AppFunctionServiceEntryPoint#getServiceName()()` The name of the generated service class. |

## 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.