CarSensors


@RequiresCarApi(value = 3)
@MainThread
public interface CarSensors


Manages access to androidx.car.app.hardware specific sensors such as compass, accelerometer, gyroscope and location.

For Android Automotive OS, the sensor APIs in this class are currently not implemented, and they will return STATUS_UNIMPLEMENTED by default. To get these values for Android Automotive OS, use SensorManager and LocationManager instead.

Summary

Constants

default static final int

Car hardware property, sensor, or action should be fetched at its fastest possible rate.

default static final int

Car hardware info, sensor, or action should be fetched at its default rate.

default static final int

Car hardware property, sensor, or action should be fetched at a rate consistent with drawing UI to a screen.

Public methods

abstract void
addAccelerometerListener(
    int rate,
    @NonNull Executor executor,
    @NonNull OnCarDataAvailableListener<Accelerometer> listener
)

Setup an ongoing listener to receive Accelerometer data from the car hardware.

abstract void

Setup an ongoing listener to receive CarHardwareLocation data from the car hardware.

abstract void
addCompassListener(
    int rate,
    @NonNull Executor executor,
    @NonNull OnCarDataAvailableListener<Compass> listener
)

Setup an ongoing listener to receive Compass data from the car hardware.

abstract void
addGyroscopeListener(
    int rate,
    @NonNull Executor executor,
    @NonNull OnCarDataAvailableListener<Gyroscope> listener
)

Setup an ongoing listener to receive Gyroscope data from the car hardware.

abstract void

Remove an ongoing listener for Accelerometer information.

abstract void

Remove an ongoing listener for CarHardwareLocation information.

abstract void

Remove an ongoing listener for Compass information.

abstract void

Remove an ongoing listener for Gyroscope information.

Constants

UPDATE_RATE_FASTEST

Added in 1.1.0
default static final int UPDATE_RATE_FASTEST = 3

Car hardware property, sensor, or action should be fetched at its fastest possible rate.

UPDATE_RATE_NORMAL

Added in 1.1.0
default static final int UPDATE_RATE_NORMAL = 1

Car hardware info, sensor, or action should be fetched at its default rate.

UPDATE_RATE_UI

Added in 1.1.0
default static final int UPDATE_RATE_UI = 2

Car hardware property, sensor, or action should be fetched at a rate consistent with drawing UI to a screen.

Public methods

addAccelerometerListener

Added in 1.1.0
abstract void addAccelerometerListener(
    int rate,
    @NonNull Executor executor,
    @NonNull OnCarDataAvailableListener<Accelerometer> listener
)

Setup an ongoing listener to receive Accelerometer data from the car hardware.

If the listener was added previously then previous rate is updated with the new rate. Use UPDATE_RATE_NORMAL as a good default rate in most cases.

Parameters
int rate

the maximum rate at which the data will be returned through the provided listener

@NonNull Executor executor

the executor which will be used for invoking the listener

@NonNull OnCarDataAvailableListener<Accelerometer> listener

the listener that will be invoked when data is available

addCarHardwareLocationListener

Added in 1.1.0
abstract void addCarHardwareLocationListener(
    int rate,
    @NonNull Executor executor,
    @NonNull OnCarDataAvailableListener<CarHardwareLocation> listener
)

Setup an ongoing listener to receive CarHardwareLocation data from the car hardware.

If the listener was added previously then previous rate is updated with the new rate. Use UPDATE_RATE_NORMAL as a good default rate in most cases.

Parameters
int rate

the maximum rate at which the data will be returned through the provided listener

@NonNull Executor executor

the executor which will be used for invoking the listener

@NonNull OnCarDataAvailableListener<CarHardwareLocation> listener

the listener that will be invoked when data is available

addCompassListener

Added in 1.1.0
abstract void addCompassListener(
    int rate,
    @NonNull Executor executor,
    @NonNull OnCarDataAvailableListener<Compass> listener
)

Setup an ongoing listener to receive Compass data from the car hardware.

If the listener was added previously then previous rate is updated with the new rate. Use UPDATE_RATE_NORMAL as a good default rate in most cases.

Parameters
int rate

the maximum rate at which the data will be returned through the provided listener

@NonNull Executor executor

the executor which will be used for invoking the listener

@NonNull OnCarDataAvailableListener<Compass> listener

the listener that will be invoked when data is available

addGyroscopeListener

Added in 1.1.0
abstract void addGyroscopeListener(
    int rate,
    @NonNull Executor executor,
    @NonNull OnCarDataAvailableListener<Gyroscope> listener
)

Setup an ongoing listener to receive Gyroscope data from the car hardware.

If the listener was added previously then previous rate is updated with the new rate. Use UPDATE_RATE_NORMAL as a good default rate in most cases.

Parameters
int rate

the maximum rate at which the data will be returned through the provided listener

@NonNull Executor executor

the executor which will be used for invoking the listener

@NonNull OnCarDataAvailableListener<Gyroscope> listener

the listener that will be invoked when data is available

removeAccelerometerListener

Added in 1.1.0
abstract void removeAccelerometerListener(
    @NonNull OnCarDataAvailableListener<Accelerometer> listener
)

Remove an ongoing listener for Accelerometer information.

If the listener is not currently added, then nothing will be removed.

Parameters
@NonNull OnCarDataAvailableListener<Accelerometer> listener

the listener to remove

removeCarHardwareLocationListener

Added in 1.1.0
abstract void removeCarHardwareLocationListener(
    @NonNull OnCarDataAvailableListener<CarHardwareLocation> listener
)

Remove an ongoing listener for CarHardwareLocation information.

If the listener is not currently added, then nothing will be removed.

Parameters
@NonNull OnCarDataAvailableListener<CarHardwareLocation> listener

the listener to remove

removeCompassListener

Added in 1.1.0
abstract void removeCompassListener(
    @NonNull OnCarDataAvailableListener<Compass> listener
)

Remove an ongoing listener for Compass information.

If the listener is not currently added, then nothing will be removed.

Parameters
@NonNull OnCarDataAvailableListener<Compass> listener

the listener to remove

removeGyroscopeListener

Added in 1.1.0
abstract void removeGyroscopeListener(
    @NonNull OnCarDataAvailableListener<Gyroscope> listener
)

Remove an ongoing listener for Gyroscope information.

If the listener is not currently added, then nothing will be removed.

Parameters
@NonNull OnCarDataAvailableListener<Gyroscope> listener

the listener to remove