Car

public final class Car
extends Object

java.lang.Object
   ↳ android.car.Car


Top level car API for embedded Android Auto deployments. This API works only for devices with PackageManager.FEATURE_AUTOMOTIVE Calling this API on a device with no such feature will lead to an exception.

Summary

Constants

String APP_FOCUS_SERVICE

Service name for CarAppFocusManager.

String AUDIO_SERVICE

Service name for CarAudioManager

String CAR_CONFIGURATION_SERVICE

Service name for CarConfigurationManager

String CAR_EXTRA_MEDIA_PACKAGE

Used as a string extra field with CAR_INTENT_ACTION_MEDIA_TEMPLATE to specify the media app that user wants to start the media on.

String CAR_INTENT_ACTION_MEDIA_TEMPLATE

Activity Action: Provide media playing through a media template app.

String CAR_NAVIGATION_SERVICE

Service name for CarNavigationStatusManager

String CAR_UX_RESTRICTION_SERVICE

Service name for CarUxRestrictionsManager

int CONNECTION_TYPE_EMBEDDED

Type of car connection: platform runs directly in car.

String INFO_SERVICE

Service name for CarInfoManager, to be used in getCarManager(String).

String PACKAGE_SERVICE

Service name for CarPackageManager

String PERMISSION_CAR_CONTROL_AUDIO_VOLUME

Permission necessary to change car audio volume through CarAudioManager.

String PERMISSION_CAR_INFO

Permission necessary to use CarInfoManager.

String PERMISSION_CAR_NAVIGATION_MANAGER

Permission necessary to use CarNavigationStatusManager.

String PERMISSION_ENERGY

Permission necessary to access car's energy information.

String PERMISSION_ENERGY_PORTS

Permission necessary to access car's fuel door and ev charge port.

String PERMISSION_EXTERIOR_ENVIRONMENT

Permission necessary to read temperature of car's exterior environment.

String PERMISSION_IDENTIFICATION

Permission necessary to access car's VIN information

String PERMISSION_POWERTRAIN

Permission necessary to access car's powertrain information.

String PERMISSION_SPEED

Permission necessary to access car's speed.

String SENSOR_SERVICE

Service name for CarSensorManager, to be used in getCarManager(String).

int VERSION

Represent the version of Car API.

Public methods

void connect()

Connect to car service.

static Car createCar(Context context, ServiceConnection serviceConnectionListener)

A factory method that creates Car instance for all Car API access using main thread Looper.

static Car createCar(Context context, ServiceConnection serviceConnectionListener, Handler handler)

A factory method that creates Car instance for all Car API access.

void disconnect()

Disconnect from car service.

int getCarConnectionType()

Return the type of currently connected car.

Object getCarManager(String serviceName)

Get car specific service as in Context.getSystemService(String).

boolean isConnected()

Tells if it is connected to the service or not.

boolean isConnecting()

Tells if this instance is already connecting to car service or not.

Inherited methods

Constants

APP_FOCUS_SERVICE

public static final String APP_FOCUS_SERVICE

Service name for CarAppFocusManager.

Constant Value: "app_focus"

AUDIO_SERVICE

public static final String AUDIO_SERVICE

Service name for CarAudioManager

Constant Value: "audio"

CAR_CONFIGURATION_SERVICE

public static final String CAR_CONFIGURATION_SERVICE

Service name for CarConfigurationManager

Constant Value: "configuration"

CAR_EXTRA_MEDIA_PACKAGE

public static final String CAR_EXTRA_MEDIA_PACKAGE

Used as a string extra field with CAR_INTENT_ACTION_MEDIA_TEMPLATE to specify the media app that user wants to start the media on. Note: this is not the templated media app.

Constant Value: "android.car.intent.extra.MEDIA_PACKAGE"

CAR_INTENT_ACTION_MEDIA_TEMPLATE

public static final String CAR_INTENT_ACTION_MEDIA_TEMPLATE

Activity Action: Provide media playing through a media template app.

Input: String extra mapped by SearchManager.QUERY is the query used to start the media. String extra mapped by CAR_EXTRA_MEDIA_PACKAGE is the package name of the media app which user wants to play media on.

Output: nothing.

Constant Value: "android.car.intent.action.MEDIA_TEMPLATE"

CAR_NAVIGATION_SERVICE

public static final String CAR_NAVIGATION_SERVICE

Service name for CarNavigationStatusManager

Constant Value: "car_navigation_service"

CAR_UX_RESTRICTION_SERVICE

public static final String CAR_UX_RESTRICTION_SERVICE

Service name for CarUxRestrictionsManager

Constant Value: "uxrestriction"

CONNECTION_TYPE_EMBEDDED

public static final int CONNECTION_TYPE_EMBEDDED

Type of car connection: platform runs directly in car.

Constant Value: 5 (0x00000005)

INFO_SERVICE

public static final String INFO_SERVICE

Service name for CarInfoManager, to be used in getCarManager(String).

Constant Value: "info"

PACKAGE_SERVICE

public static final String PACKAGE_SERVICE

Service name for CarPackageManager

Constant Value: "package"

PERMISSION_CAR_CONTROL_AUDIO_VOLUME

public static final String PERMISSION_CAR_CONTROL_AUDIO_VOLUME

Permission necessary to change car audio volume through CarAudioManager.

Constant Value: "android.car.permission.CAR_CONTROL_AUDIO_VOLUME"

PERMISSION_CAR_INFO

public static final String PERMISSION_CAR_INFO

Permission necessary to use CarInfoManager.

Constant Value: "android.car.permission.CAR_INFO"

PERMISSION_CAR_NAVIGATION_MANAGER

public static final String PERMISSION_CAR_NAVIGATION_MANAGER

Permission necessary to use CarNavigationStatusManager.

Constant Value: "android.car.permission.CAR_NAVIGATION_MANAGER"

PERMISSION_ENERGY

public static final String PERMISSION_ENERGY

Permission necessary to access car's energy information.

Constant Value: "android.car.permission.CAR_ENERGY"

PERMISSION_ENERGY_PORTS

public static final String PERMISSION_ENERGY_PORTS

Permission necessary to access car's fuel door and ev charge port.

Constant Value: "android.car.permission.CAR_ENERGY_PORTS"

PERMISSION_EXTERIOR_ENVIRONMENT

public static final String PERMISSION_EXTERIOR_ENVIRONMENT

Permission necessary to read temperature of car's exterior environment.

Constant Value: "android.car.permission.CAR_EXTERIOR_ENVIRONMENT"

PERMISSION_IDENTIFICATION

public static final String PERMISSION_IDENTIFICATION

Permission necessary to access car's VIN information

Constant Value: "android.car.permission.CAR_IDENTIFICATION"

PERMISSION_POWERTRAIN

public static final String PERMISSION_POWERTRAIN

Permission necessary to access car's powertrain information.

Constant Value: "android.car.permission.CAR_POWERTRAIN"

PERMISSION_SPEED

public static final String PERMISSION_SPEED

Permission necessary to access car's speed.

Constant Value: "android.car.permission.CAR_SPEED"

SENSOR_SERVICE

public static final String SENSOR_SERVICE

Service name for CarSensorManager, to be used in getCarManager(String).

Constant Value: "sensor"

VERSION

public static final int VERSION

Represent the version of Car API. This is only updated when there is API change. 1 : N 2 : O 3 : O-MR1

Constant Value: 3 (0x00000003)

Public methods

connect

public void connect ()

Connect to car service. This can be called while it is disconnected.

Throws
IllegalStateException If connection is still on-going from previous connect call or it is already connected

createCar

public static Car createCar (Context context, 
                ServiceConnection serviceConnectionListener)

A factory method that creates Car instance for all Car API access using main thread Looper.

Parameters
context Context

serviceConnectionListener ServiceConnection

Returns
Car

createCar

public static Car createCar (Context context, 
                ServiceConnection serviceConnectionListener, 
                Handler handler)

A factory method that creates Car instance for all Car API access.

Parameters
serviceConnectionListener ServiceConnection: listener for monitoring service connection.

handler Handler: the handler on which the callback should execute, or null to execute on the service's main thread. Note: the service connection listener will be always on the main thread regardless of the handler given.

Returns
Car Car instance if system is in car environment and returns null otherwise.

disconnect

public void disconnect ()

Disconnect from car service. This can be called while disconnected. Once disconnect is called, all Car*Managers from this instance becomes invalid, and getCarManager(String) will return different instance if it is connected again.

getCarConnectionType

public int getCarConnectionType ()

Return the type of currently connected car.

Returns
int

getCarManager

public Object getCarManager (String serviceName)

Get car specific service as in Context.getSystemService(String). Returned Object should be type-casted to the desired service. For example, to get sensor service, SensorManagerService sensorManagerService = car.getCarManager(Car.SENSOR_SERVICE);

Parameters
serviceName String: Name of service that should be created like SENSOR_SERVICE.

Returns
Object Matching service manager or null if there is no such service.

Throws
CarNotConnectedException if the connection to the car service has been lost.

isConnected

public boolean isConnected ()

Tells if it is connected to the service or not. This will return false if it is still connecting.

Returns
boolean

isConnecting

public boolean isConnecting ()

Tells if this instance is already connecting to car service or not.

Returns
boolean