CarConnection

public final class CarConnection
extends Object

java.lang.Object
   ↳ androidx.car.app.connection.CarConnection


A class that allows retrieval of information about connection to a car head unit.

Summary

Constants

String ACTION_CAR_CONNECTION_UPDATED

Broadcast action that notifies that the car connection has changed and needs to be updated.

String CAR_CONNECTION_STATE

Defines current car connection state.

int CONNECTION_TYPE_NATIVE

Natively running on a head unit (Android Automotive OS).

int CONNECTION_TYPE_NOT_CONNECTED

Not connected to any car head unit.z

int CONNECTION_TYPE_PROJECTION

Connected to a car head unit by projecting to it.

Public constructors

CarConnection(Context context)

Constructs a CarConnection that can be used to get connection information.

Public methods

LiveData<Integer> getType()

Returns a LiveData that can be observed to get current connection type.

Inherited methods

Constants

ACTION_CAR_CONNECTION_UPDATED

public static final String ACTION_CAR_CONNECTION_UPDATED

Broadcast action that notifies that the car connection has changed and needs to be updated.

Constant Value: "androidx.car.app.connection.action.CAR_CONNECTION_UPDATED"

CAR_CONNECTION_STATE

public static final String CAR_CONNECTION_STATE

Defines current car connection state.

This is used for communication with the car host's content provider on queries for connection type.

Constant Value: "CarConnectionState"

CONNECTION_TYPE_NATIVE

public static final int CONNECTION_TYPE_NATIVE

Natively running on a head unit (Android Automotive OS).

Constant Value: 1 (0x00000001)

CONNECTION_TYPE_NOT_CONNECTED

public static final int CONNECTION_TYPE_NOT_CONNECTED

Not connected to any car head unit.z

Constant Value: 0 (0x00000000)

CONNECTION_TYPE_PROJECTION

public static final int CONNECTION_TYPE_PROJECTION

Connected to a car head unit by projecting to it.

Constant Value: 2 (0x00000002)

Public constructors

CarConnection

public CarConnection (Context context)

Constructs a CarConnection that can be used to get connection information.

Parameters
context Context

Throws
NullPointerException if context is null

Public methods

getType

public 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:

  1. CONNECTION_TYPE_NOT_CONNECTED
  2. CONNECTION_TYPE_NATIVE
  3. CONNECTION_TYPE_PROJECTION

Returns
LiveData<Integer>