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 |
UPDATE_RATE_UI = 2Car hardware property, sensor, or action should be fetched at a rate consistent with drawing UI to a screen. |
Public functions |
|
|---|---|
Unit |
addAccelerometerListener(Setup an ongoing listener to receive |
Unit |
addCarHardwareLocationListener(Setup an ongoing listener to receive |
Unit |
addCompassListener(Setup an ongoing listener to receive |
Unit |
addGyroscopeListener(Setup an ongoing listener to receive |
Unit |
Remove an ongoing listener for |
Unit |
Remove an ongoing listener for |
Unit |
removeCompassListener(listener: OnCarDataAvailableListener<Compass!>)Remove an ongoing listener for |
Unit |
removeGyroscopeListener(Remove an ongoing listener for |
Constants
UPDATE_RATE_FASTEST
const val UPDATE_RATE_FASTEST = 3: Int
Car hardware property, sensor, or action should be fetched at its fastest possible rate.
UPDATE_RATE_NORMAL
const val UPDATE_RATE_NORMAL = 1: Int
Car hardware info, sensor, or action should be fetched at its default rate.
UPDATE_RATE_UI
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
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
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
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
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
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
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
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
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 |