CarSensors

@RequiresCarApi(value = 3)
@MainThread
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

const Int

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

const Int

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

const Int

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

Public functions

Unit
addAccelerometerListener(
    rate: Int,
    executor: Executor,
    listener: OnCarDataAvailableListener<Accelerometer!>
)

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

Unit
addCarHardwareLocationListener(
    rate: Int,
    executor: Executor,
    listener: OnCarDataAvailableListener<CarHardwareLocation!>
)

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

Unit
addCompassListener(
    rate: Int,
    executor: Executor,
    listener: OnCarDataAvailableListener<Compass!>
)

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

Unit
addGyroscopeListener(
    rate: Int,
    executor: Executor,
    listener: OnCarDataAvailableListener<Gyroscope!>
)

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

Unit

Remove an ongoing listener for Accelerometer information.

Unit

Remove an ongoing listener for CarHardwareLocation information.

Unit

Remove an ongoing listener for Compass information.

Unit

Remove an ongoing listener for Gyroscope information.

Constants

UPDATE_RATE_FASTEST

Added in 1.1.0
const val UPDATE_RATE_FASTEST = 3: Int

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

UPDATE_RATE_NORMAL

Added in 1.1.0
const val UPDATE_RATE_NORMAL = 1: Int

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

UPDATE_RATE_UI

Added in 1.1.0
const val UPDATE_RATE_UI = 2: Int

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

Public functions

addAccelerometerListener

Added in 1.1.0
fun addAccelerometerListener(
    rate: Int,
    executor: Executor,
    listener: OnCarDataAvailableListener<Accelerometer!>
): Unit

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
rate: Int

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

executor: Executor

the executor which will be used for invoking the listener

listener: OnCarDataAvailableListener<Accelerometer!>

the listener that will be invoked when data is available

addCarHardwareLocationListener

Added in 1.1.0
fun addCarHardwareLocationListener(
    rate: Int,
    executor: Executor,
    listener: OnCarDataAvailableListener<CarHardwareLocation!>
): Unit

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
rate: Int

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

executor: Executor

the executor which will be used for invoking the listener

listener: OnCarDataAvailableListener<CarHardwareLocation!>

the listener that will be invoked when data is available

addCompassListener

Added in 1.1.0
fun addCompassListener(
    rate: Int,
    executor: Executor,
    listener: OnCarDataAvailableListener<Compass!>
): Unit

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
rate: Int

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

executor: Executor

the executor which will be used for invoking the listener

listener: OnCarDataAvailableListener<Compass!>

the listener that will be invoked when data is available

addGyroscopeListener

Added in 1.1.0
fun addGyroscopeListener(
    rate: Int,
    executor: Executor,
    listener: OnCarDataAvailableListener<Gyroscope!>
): Unit

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
rate: Int

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

executor: Executor

the executor which will be used for invoking the listener

listener: OnCarDataAvailableListener<Gyroscope!>

the listener that will be invoked when data is available

removeAccelerometerListener

Added in 1.1.0
fun removeAccelerometerListener(
    listener: OnCarDataAvailableListener<Accelerometer!>
): Unit

Remove an ongoing listener for Accelerometer information.

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

Parameters
listener: OnCarDataAvailableListener<Accelerometer!>

the listener to remove

removeCarHardwareLocationListener

Added in 1.1.0
fun removeCarHardwareLocationListener(
    listener: OnCarDataAvailableListener<CarHardwareLocation!>
): Unit

Remove an ongoing listener for CarHardwareLocation information.

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

Parameters
listener: OnCarDataAvailableListener<CarHardwareLocation!>

the listener to remove

removeCompassListener

Added in 1.1.0
fun removeCompassListener(listener: OnCarDataAvailableListener<Compass!>): Unit

Remove an ongoing listener for Compass information.

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

Parameters
listener: OnCarDataAvailableListener<Compass!>

the listener to remove

removeGyroscopeListener

Added in 1.1.0
fun removeGyroscopeListener(
    listener: OnCarDataAvailableListener<Gyroscope!>
): Unit

Remove an ongoing listener for Gyroscope information.

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

Parameters
listener: OnCarDataAvailableListener<Gyroscope!>

the listener to remove