O Google tem o compromisso de promover a igualdade racial para as comunidades negras. Saiba como.

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

Nested classes

interface Car.CarServiceLifecycleListener

Callback to notify the Lifecycle of car service. 

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_BROWSE_SERVICE_FOR_SESSION

Used as a string extra field of media session to specify the service corresponding to the session.

String CAR_EXTRA_MEDIA_COMPONENT

Used as a string extra field with CAR_INTENT_ACTION_MEDIA_TEMPLATE to specify the MediaBrowserService 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 ERROR(CarNavigationStatusManager/android.car.navigation.CarNavigationStatusManager CarNavigationStatusManager)

String CAR_OCCUPANT_ZONE_SERVICE

Service name for CarOccupantZoneManager

String CAR_UX_RESTRICTION_SERVICE

Service name for CarUxRestrictionsManager

long CAR_WAIT_TIMEOUT_DO_NOT_WAIT

createCar(android.content.Context, android.os.Handler, long, android.car.Car.CarServiceLifecycleListener)'s waitTimeoutMs value to use to skip any waiting inside the call.

long CAR_WAIT_TIMEOUT_WAIT_FOREVER

createCar(android.content.Context, android.os.Handler, long, android.car.Car.CarServiceLifecycleListener)'s waitTimeoutMs value to use to wait forever inside the call until car service is ready.

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(java.lang.String).

String META_DATA_DISTRACTION_OPTIMIZED

This represents AndroidManifest meta-data to tell that Activity is optimized for driving distraction.

String META_DATA_REQUIRES_CAR_FEATURE

This represents AndroidManifest meta-data to tell that Application requires specific car features to work.

String PACKAGE_SERVICE

Service name for CarPackageManager

String PERMISSION_CAR_CONTROL_AUDIO_SETTINGS

Permission necessary to change car audio settings through CarAudioManager.

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 ERROR(CarNavigationStatusManager/android.car.navigation.CarNavigationStatusManager CarNavigationStatusManager).

String PERMISSION_CONTROL_DISPLAY_UNITS

Permission necessary to control display units for distance, fuel volume, tire pressure and ev battery.

String PERMISSION_CONTROL_INTERIOR_LIGHTS

Permission necessary to control car's interior lights.

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_READ_DISPLAY_UNITS

Permission necessary to read and write display units for distance, fuel volume, tire pressure and ev battery.

String PERMISSION_READ_INTERIOR_LIGHTS

Permission necessary to read car's interior lights information.

String PERMISSION_READ_STEERING_STATE

Permission necessary to access car's steering angle information.

String PERMISSION_SPEED

Permission necessary to access car's speed.

String PROPERTY_SERVICE

Service name for CarPropertyManager

String SENSOR_SERVICE

This constant was deprecated in API level 29. CarSensorManager is deprecated. Use CarPropertyManager instead.

Public methods

void connect()

This method was deprecated in API level 29. this method is not need if this object is created via createCar(android.content.Context, android.os.Handler).

static Car createCar(Context context, Handler handler)

Creates new Car object which connected synchronously to Car Service and ready to use.

static Car createCar(Context context)

Creates new Car object which connected synchronously to Car Service and ready to use.

static Car createCar(Context context, ServiceConnection serviceConnectionListener)

This method was deprecated in API level 29. use createCar(android.content.Context, android.os.Handler) instead.

static Car createCar(Context context, Handler handler, long waitTimeoutMs, Car.CarServiceLifecycleListener statusChangeListener)

Creates new Car object with CarServiceLifecycleListener.

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

This method was deprecated in API level 29. use createCar(android.content.Context, android.os.Handler) instead.

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.

boolean isFeatureEnabled(String featureName)

Checks if {code featureName} is enabled in this car.

Inherited methods

Constants

APP_FOCUS_SERVICE

Added in API level 29
public static final String APP_FOCUS_SERVICE

Service name for CarAppFocusManager.

Constant Value: "app_focus"

AUDIO_SERVICE

Added in API level 29
public static final String AUDIO_SERVICE

Service name for CarAudioManager

Constant Value: "audio"

CAR_CONFIGURATION_SERVICE

Added in API level 29
public static final String CAR_CONFIGURATION_SERVICE

Service name for CarConfigurationManager

Constant Value: "configuration"

CAR_EXTRA_BROWSE_SERVICE_FOR_SESSION

public static final String CAR_EXTRA_BROWSE_SERVICE_FOR_SESSION

Used as a string extra field of media session to specify the service corresponding to the session.

Constant Value: "android.media.session.BROWSE_SERVICE"

CAR_EXTRA_MEDIA_COMPONENT

public static final String CAR_EXTRA_MEDIA_COMPONENT

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

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

CAR_INTENT_ACTION_MEDIA_TEMPLATE

Added in API level 29
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_COMPONENT is the component 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

Added in API level 29
public static final String CAR_NAVIGATION_SERVICE

Service name for ERROR(CarNavigationStatusManager/android.car.navigation.CarNavigationStatusManager CarNavigationStatusManager)

Constant Value: "car_navigation_service"

CAR_OCCUPANT_ZONE_SERVICE

public static final String CAR_OCCUPANT_ZONE_SERVICE

Service name for CarOccupantZoneManager

Constant Value: "car_occupant_zone_service"

CAR_UX_RESTRICTION_SERVICE

Added in API level 29
public static final String CAR_UX_RESTRICTION_SERVICE

Service name for CarUxRestrictionsManager

Constant Value: "uxrestriction"

CAR_WAIT_TIMEOUT_DO_NOT_WAIT

public static final long CAR_WAIT_TIMEOUT_DO_NOT_WAIT

createCar(android.content.Context, android.os.Handler, long, android.car.Car.CarServiceLifecycleListener)'s waitTimeoutMs value to use to skip any waiting inside the call.

Constant Value: 0 (0x0000000000000000)

CAR_WAIT_TIMEOUT_WAIT_FOREVER

public static final long CAR_WAIT_TIMEOUT_WAIT_FOREVER

createCar(android.content.Context, android.os.Handler, long, android.car.Car.CarServiceLifecycleListener)'s waitTimeoutMs value to use to wait forever inside the call until car service is ready.

Constant Value: -1 (0xffffffffffffffff)

CONNECTION_TYPE_EMBEDDED

Added in API level 29
public static final int CONNECTION_TYPE_EMBEDDED

Type of car connection: platform runs directly in car.

Constant Value: 5 (0x00000005)

INFO_SERVICE

Added in API level 29
public static final String INFO_SERVICE

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

Constant Value: "info"

META_DATA_DISTRACTION_OPTIMIZED

public static final String META_DATA_DISTRACTION_OPTIMIZED

This represents AndroidManifest meta-data to tell that Activity is optimized for driving distraction.

Activities without this meta-data can be blocked while car is in moving / driving state.

Note that having this flag does not guarantee that the Activity will be always allowed for all driving states.

For this meta-data, android:value can be true (=optimized) or false.

Example usage:

Constant Value: "distractionOptimized"

META_DATA_REQUIRES_CAR_FEATURE

public static final String META_DATA_REQUIRES_CAR_FEATURE

This represents AndroidManifest meta-data to tell that Application requires specific car features to work.

Apps like launcher or installer app can use this information to filter out apps not usable in a specific car. This meta-data is not necessary for mandatory features.

For this meta-data, android:value should contain the feature name string defined by (@link android.car.annotation.OptionalFeature} or ERROR(/android.car.annotation.ExperimentalFeature) annotations.

Example usage:

Constant Value: "requires-car-feature"

PACKAGE_SERVICE

Added in API level 29
public static final String PACKAGE_SERVICE

Service name for CarPackageManager

Constant Value: "package"

PERMISSION_CAR_CONTROL_AUDIO_SETTINGS

Added in API level 29
public static final String PERMISSION_CAR_CONTROL_AUDIO_SETTINGS

Permission necessary to change car audio settings through CarAudioManager.

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

PERMISSION_CAR_CONTROL_AUDIO_VOLUME

Added in API level 29
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

Added in API level 29
public static final String PERMISSION_CAR_INFO

Permission necessary to use CarInfoManager.

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

PERMISSION_CAR_NAVIGATION_MANAGER

Added in API level 29
public static final String PERMISSION_CAR_NAVIGATION_MANAGER

Permission necessary to use ERROR(CarNavigationStatusManager/android.car.navigation.CarNavigationStatusManager CarNavigationStatusManager).

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

PERMISSION_CONTROL_DISPLAY_UNITS

Added in API level 29
public static final String PERMISSION_CONTROL_DISPLAY_UNITS

Permission necessary to control display units for distance, fuel volume, tire pressure and ev battery.

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

PERMISSION_CONTROL_INTERIOR_LIGHTS

Added in API level 29
public static final String PERMISSION_CONTROL_INTERIOR_LIGHTS

Permission necessary to control car's interior lights.

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

PERMISSION_ENERGY

Added in API level 29
public static final String PERMISSION_ENERGY

Permission necessary to access car's energy information.

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

PERMISSION_ENERGY_PORTS

Added in API level 29
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

Added in API level 29
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

Added in API level 29
public static final String PERMISSION_IDENTIFICATION

Permission necessary to access car's VIN information

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

PERMISSION_POWERTRAIN

Added in API level 29
public static final String PERMISSION_POWERTRAIN

Permission necessary to access car's powertrain information.

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

PERMISSION_READ_DISPLAY_UNITS

Added in API level 29
public static final String PERMISSION_READ_DISPLAY_UNITS

Permission necessary to read and write display units for distance, fuel volume, tire pressure and ev battery.

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

PERMISSION_READ_INTERIOR_LIGHTS

Added in API level 29
public static final String PERMISSION_READ_INTERIOR_LIGHTS

Permission necessary to read car's interior lights information.

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

PERMISSION_READ_STEERING_STATE

Added in API level 29
public static final String PERMISSION_READ_STEERING_STATE

Permission necessary to access car's steering angle information.

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

PERMISSION_SPEED

Added in API level 29
public static final String PERMISSION_SPEED

Permission necessary to access car's speed.

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

PROPERTY_SERVICE

Added in API level 29
public static final String PROPERTY_SERVICE

Service name for CarPropertyManager

Constant Value: "property"

SENSOR_SERVICE

Added in API level 29
Deprecated in API level 29
public static final String SENSOR_SERVICE

This constant was deprecated in API level 29.
CarSensorManager is deprecated. Use CarPropertyManager instead.

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

Constant Value: "sensor"

Public methods

connect

Added in API level 29
Deprecated in API level 29
public void connect ()

This method was deprecated in API level 29.
this method is not need if this object is created via createCar(android.content.Context, android.os.Handler).

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

Added in API level 29
public static Car createCar (Context context, 
                Handler handler)

Creates new Car object which connected synchronously to Car Service and ready to use.

Instance created with this should be disconnected from car service by calling disconnect() before the passed {code Context} is released.

Parameters
context Context: App's Context. This should not be null. If you are passing ContextWrapper, make sure that its base Context is non-null as well. Otherwise it will throw NullPointerException.

handler Handler: the handler on which the manager's callbacks will be executed, or null to execute on the application's main thread.

Returns
Car Car object if operation succeeded, otherwise null.

createCar

Added in API level 29
public static Car createCar (Context context)

Creates new Car object which connected synchronously to Car Service and ready to use.

Instance created with this should be disconnected from car service by calling disconnect() before the passed {code Context} is released.

Parameters
context Context: application's context

Returns
Car Car object if operation succeeded, otherwise null.

createCar

Added in API level 29
Deprecated in API level 29
public static Car createCar (Context context, 
                ServiceConnection serviceConnectionListener)

This method was deprecated in API level 29.
use createCar(android.content.Context, android.os.Handler) instead.

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

Instance created with this should be disconnected from car service by calling disconnect() before the passed {code Context} is released.

Parameters
context Context

serviceConnectionListener ServiceConnection

Returns
Car

createCar

public static Car createCar (Context context, 
                Handler handler, 
                long waitTimeoutMs, 
                Car.CarServiceLifecycleListener statusChangeListener)

Creates new Car object with CarServiceLifecycleListener.

Instance created with this should be disconnected from car service by calling disconnect() before the passed {code Context} is released.

If car service is ready inside this call and if the caller is running in the main thread, CarServiceLifecycleListener#onLifecycleChanged(Car, boolean) will be called with ready set to be true. Otherwise, CarServiceLifecycleListener#onLifecycleChanged(Car, boolean) will be called from the main thread later.

This call can block up to specified waitTimeoutMs to wait for car service to be ready. If car service is not ready within the given time, it will return a Car instance in disconnected state. Blocking main thread forever can lead into getting ANR (Application Not Responding) killing from system and should not be used if the app is supposed to survive across the crash / restart of car service. It can be still useful in case the app cannot do anything without car service being ready. In any waiting, if the thread is getting interrupted, it will return immediately.

Note that returned Car object is not guaranteed to be connected when there is a limited timeout. Regardless of returned car being connected or not, it is recommended to implement all car related initialization inside CarServiceLifecycleListener#onLifecycleChanged(Car, boolean) and avoid the needs to check if returned Car is connected or not from returned Car.

Parameters
context Context: App's Context. This should not be null. If you are passing ContextWrapper, make sure that its base Context is non-null as well. Otherwise it will throw NullPointerException.

handler Handler: dispatches all Car*Manager events to this Handler. Exception is CarServiceLifecycleListener which will be always dispatched to main thread. Passing null leads into dispatching all Car*Manager callbacks to main thread as well.

waitTimeoutMs long: Setting this to CAR_WAIT_TIMEOUT_DO_NOT_WAIT will guarantee that the API does not wait for the car service at all. Setting this to to CAR_WAIT_TIMEOUT_WAIT_FOREVER will block the call forever until the car service is ready. Setting any positive value will be interpreted as timeout value.

statusChangeListener Car.CarServiceLifecycleListener

Returns
Car

createCar

Added in API level 29
Deprecated in API level 29
public static Car createCar (Context context, 
                ServiceConnection serviceConnectionListener, 
                Handler handler)

This method was deprecated in API level 29.
use createCar(android.content.Context, android.os.Handler) instead.

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

Instance created with this should be disconnected from car service by calling disconnect() before the passed {code Context} is released.

Parameters
context Context: App's Context. This should not be null. If you are passing ContextWrapper, make sure that its base Context is non-null as well. Otherwise it will throw NullPointerException.

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

Added in API level 29
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 Car#getCarManager(String) will return different instance if it is connected again.

getCarConnectionType

Added in API level 29
public int getCarConnectionType ()

Return the type of currently connected car.

Returns
int Value is CONNECTION_TYPE_EMBEDDED

getCarManager

Added in API level 29
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.

isConnected

Added in API level 29
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

Added in API level 29
public boolean isConnecting ()

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

Returns
boolean

isFeatureEnabled

public boolean isFeatureEnabled (String featureName)

Checks if {code featureName} is enabled in this car.

For optional features, this can return false if the car cannot support it. Optional features should be used only when they are supported.

For mandatory features, this will always return true.

Parameters
featureName String

Returns
boolean