CarConnection
public final class CarConnection
A class that allows retrieval of information about connection to a car head unit.
Summary
Constants |
|
|---|---|
static final String |
ACTION_CAR_CONNECTION_UPDATED = "androidx.car.app.connection.action.CAR_CONNECTION_UPDATED"Broadcast action that notifies that the car connection has changed and needs to be updated. |
static final String |
CAR_CONNECTION_STATE = "CarConnectionState"Defines current car connection state. |
static final int |
Natively running on a head unit (Android Automotive OS). |
static final int |
Not connected to any car head unit. |
static final int |
Connected to a car head unit by projecting to it. |
Public constructors |
|---|
@MainThreadConstructs a |
Public methods |
|
|---|---|
@NonNull LiveData<Integer> |
getType()Returns a |
Constants
ACTION_CAR_CONNECTION_UPDATED
public static final String ACTION_CAR_CONNECTION_UPDATED = "androidx.car.app.connection.action.CAR_CONNECTION_UPDATED"
Broadcast action that notifies that the car connection has changed and needs to be updated.
CAR_CONNECTION_STATE
public static final String CAR_CONNECTION_STATE = "CarConnectionState"
Defines current car connection state.
This is used for communication with the car host's content provider on queries for connection type.
CONNECTION_TYPE_NATIVE
public static final int CONNECTION_TYPE_NATIVE = 1
Natively running on a head unit (Android Automotive OS).
CONNECTION_TYPE_NOT_CONNECTED
public static final int CONNECTION_TYPE_NOT_CONNECTED = 0
Not connected to any car head unit.
CONNECTION_TYPE_PROJECTION
public static final int CONNECTION_TYPE_PROJECTION = 2
Connected to a car head unit by projecting to it.
Public constructors
CarConnection
@MainThread
public CarConnection(@NonNull Context context)
Constructs a CarConnection that can be used to get connection information.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
Public methods
getType
public @NonNull LiveData<Integer> getType()
Returns a LiveData that can be observed to get current connection type.
The recommended pattern is to observe the LiveData with the activity's lifecycle in order to get updates on the state change throughout the activity's lifetime.
Connection types are: