# 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])
annotation AppFunctionServiceEntryPoint
```

<br />

*** ** * ** ***

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

This annotation helps generate a service, bridging `https://developer.android.com/reference/kotlin/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/kotlin/androidx/appfunctions/AppFunctionDeclaration`-annotated methods defined in the same class.

### Example

First, define your service:

```kotlin
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`:

```kotlin
<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/kotlin/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/kotlin/androidx/appfunctions/AppFunctionManager#setAppFunctionEnabled(kotlin.String,kotlin.Int)` are also available in the companion object. The generated service has the following structure:

```kotlin
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/kotlin/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.

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

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionServiceEntryPoint#AppFunctionServiceEntryPoint(kotlin.String,kotlin.String)( serviceName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, appFunctionXmlFileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionServiceEntryPoint#appFunctionXmlFileName()` The name of the generated app function XML file. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionServiceEntryPoint#serviceName()` The name of the generated service class. |

## Public constructors

### AppFunctionServiceEntryPoint

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
AppFunctionServiceEntryPoint(
    serviceName: String,
    appFunctionXmlFileName: String
)
```

| Parameters |
|---|---|
| `serviceName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The name of the generated service class. |
| `appFunctionXmlFileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The name of the generated app function XML file. |

## Public properties

### appFunctionXmlFileName

```
val appFunctionXmlFileName: String
```

The name of the generated app function XML file.

### serviceName

```
val serviceName: String
```

The name of the generated service class.