CarAppService

public abstract class CarAppService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ androidx.car.app.CarAppService


The base class for implementing a car app that runs in the car.

Service Declaration

The app must extend the CarAppService to be bound by the car host. The service must also respond to Intent actions coming from the host, by adding an intent-filter to the service in the AndroidManifest.xml that handles the SERVICE_INTERFACE action. The app must also declare what category of application it is (e.g. CATEGORY_NAVIGATION_APP). For example:
<service
   android:name=".YourAppService"
   android:exported="true">
   <intent-filter>
     <action android:name="androidx.car.app.CarAppService" />
     <category android:name="androidx.car.app.category.NAVIGATION"/>
   </intent-filter>
 </service>
 

For a list of all the supported categories see Supported App Categories.

Accessing Location

When the app is running in the car display, the system will not consider it as being in the foreground, and hence it will be considered in the background for the purpose of retrieving location as described here.

To reliably get location for your car app, we recommended that you use a foreground service. Also note that accessing location may become unreliable when the phone is in the battery saver mode.

Summary

Constants

String CATEGORY_CHARGING_APP

Used to declare that this app is a charging app in the manifest.

String CATEGORY_NAVIGATION_APP

Used to declare that this app is a navigation app in the manifest.

String CATEGORY_PARKING_APP

Used to declare that this app is a parking app in the manifest.

String SERVICE_INTERFACE

The full qualified name of the CarAppService class.

Inherited constants

Public constructors

CarAppService()

Public methods

abstract HostValidator createHostValidator()

Returns the HostValidator this service will use to accept or reject host connections.

final void dump(FileDescriptor fd, PrintWriter writer, String[] args)
final Session getCurrentSession()

Returns the current Session for this service.

final HostInfo getHostInfo()

Returns information about the host attached to this service.

final IBinder onBind(Intent intent)

Handles the host binding to this car app.

abstract Session onCreateSession()

Creates a new Session for the application.

final boolean onUnbind(Intent intent)

Handles the host unbinding from this car app.

Inherited methods