# CarSensors

# CarSensors

Artifact:[androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app)  
[View Source](https://cs.android.com/search?q=file:androidx/car/app/hardware/info/CarSensors.java+class:androidx.car.app.hardware.info.CarSensors)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/car/app/hardware/info/CarSensors "View this page in Java")

<br />

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

<br />

*** ** * ** ***

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](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/CarValue#STATUS_UNIMPLEMENTED())by default. To get these values for Android Automotive OS, use[SensorManager](https://developer.android.com/reference/android/hardware/SensorManager)and[LocationManager](https://developer.android.com/reference/android/location/LocationManager)instead.

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [UPDATE_RATE_FASTEST](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#UPDATE_RATE_FASTEST())` = 3` Car hardware property, sensor, or action should be fetched at its fastest possible rate.           |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [UPDATE_RATE_NORMAL](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#UPDATE_RATE_NORMAL())` = 1` Car hardware info, sensor, or action should be fetched at its default rate.                          |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [UPDATE_RATE_UI](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#UPDATE_RATE_UI())` = 2` Car hardware property, sensor, or action should be fetched at a rate consistent with drawing UI to a screen. |

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [addAccelerometerListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#addAccelerometerListener(int,java.util.concurrent.Executor,androidx.car.app.hardware.common.OnCarDataAvailableListener<androidx.car.app.hardware.info.Accelerometer>))`(` ` rate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` executor: `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html)`,` ` listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Accelerometer](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Accelerometer)`!>` `)` Setup an ongoing listener to receive[Accelerometer](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Accelerometer)data from the car hardware.                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [addCarHardwareLocationListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#addCarHardwareLocationListener(int,java.util.concurrent.Executor,androidx.car.app.hardware.common.OnCarDataAvailableListener<androidx.car.app.hardware.info.CarHardwareLocation>))`(` ` rate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` executor: `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html)`,` ` listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[CarHardwareLocation](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarHardwareLocation)`!>` `)` Setup an ongoing listener to receive[CarHardwareLocation](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarHardwareLocation)data from the car hardware. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [addCompassListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#addCompassListener(int,java.util.concurrent.Executor,androidx.car.app.hardware.common.OnCarDataAvailableListener<androidx.car.app.hardware.info.Compass>))`(` ` rate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` executor: `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html)`,` ` listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Compass](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Compass)`!>` `)` Setup an ongoing listener to receive[Compass](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Compass)data from the car hardware.                                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [addGyroscopeListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#addGyroscopeListener(int,java.util.concurrent.Executor,androidx.car.app.hardware.common.OnCarDataAvailableListener<androidx.car.app.hardware.info.Gyroscope>))`(` ` rate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` executor: `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html)`,` ` listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Gyroscope](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Gyroscope)`!>` `)` Setup an ongoing listener to receive[Gyroscope](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Gyroscope)data from the car hardware.                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [removeAccelerometerListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#removeAccelerometerListener(androidx.car.app.hardware.common.OnCarDataAvailableListener<androidx.car.app.hardware.info.Accelerometer>))`(` ` listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Accelerometer](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Accelerometer)`!>` `)` Remove an ongoing listener for[Accelerometer](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Accelerometer)information.                                                                                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [removeCarHardwareLocationListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#removeCarHardwareLocationListener(androidx.car.app.hardware.common.OnCarDataAvailableListener<androidx.car.app.hardware.info.CarHardwareLocation>))`(` ` listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[CarHardwareLocation](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarHardwareLocation)`!>` `)` Remove an ongoing listener for[CarHardwareLocation](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarHardwareLocation)information.                                                                                                                                                                                                                                                 |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [removeCompassListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#removeCompassListener(androidx.car.app.hardware.common.OnCarDataAvailableListener<androidx.car.app.hardware.info.Compass>))`(listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Compass](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Compass)`!>)` Remove an ongoing listener for[Compass](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Compass)information.                                                                                                                                                                                                                                                                                                                                            |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [removeGyroscopeListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#removeGyroscopeListener(androidx.car.app.hardware.common.OnCarDataAvailableListener<androidx.car.app.hardware.info.Gyroscope>))`(` ` listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Gyroscope](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Gyroscope)`!>` `)` Remove an ongoing listener for[Gyroscope](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Gyroscope)information.                                                                                                                                                                                                                                                                                                                       |

## Constants

### UPDATE_RATE_FASTEST

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#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](https://developer.android.com/jetpack/androidx/releases/car-app#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](https://developer.android.com/jetpack/androidx/releases/car-app#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](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)  

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

Setup an ongoing listener to receive[Accelerometer](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/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](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#UPDATE_RATE_NORMAL())as a good default`rate`in most cases.  

|                                                                                                                               Parameters                                                                                                                                |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| `rate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                     | the maximum rate at which the data will be returned through the provided listener |
| `executor: `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html)                                                                                                                                                                      | the executor which will be used for invoking the listener                         |
| `listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Accelerometer](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Accelerometer)`!>` | the listener that will be invoked when data is available                          |

### addCarHardwareLocationListener

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)  

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

Setup an ongoing listener to receive[CarHardwareLocation](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/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](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#UPDATE_RATE_NORMAL())as a good default`rate`in most cases.  

|                                                                                                                                     Parameters                                                                                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| `rate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                                 | the maximum rate at which the data will be returned through the provided listener |
| `executor: `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html)                                                                                                                                                                                  | the executor which will be used for invoking the listener                         |
| `listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[CarHardwareLocation](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarHardwareLocation)`!>` | the listener that will be invoked when data is available                          |

### addCompassListener

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)  

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

Setup an ongoing listener to receive[Compass](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/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](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#UPDATE_RATE_NORMAL())as a good default`rate`in most cases.  

|                                                                                                                         Parameters                                                                                                                          |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| `rate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                         | the maximum rate at which the data will be returned through the provided listener |
| `executor: `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html)                                                                                                                                                          | the executor which will be used for invoking the listener                         |
| `listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Compass](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Compass)`!>` | the listener that will be invoked when data is available                          |

### addGyroscopeListener

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)  

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

Setup an ongoing listener to receive[Gyroscope](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/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](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarSensors#UPDATE_RATE_NORMAL())as a good default`rate`in most cases.  

|                                                                                                                           Parameters                                                                                                                            |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| `rate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                             | the maximum rate at which the data will be returned through the provided listener |
| `executor: `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor.html)                                                                                                                                                              | the executor which will be used for invoking the listener                         |
| `listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Gyroscope](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Gyroscope)`!>` | the listener that will be invoked when data is available                          |

### removeAccelerometerListener

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)  

```
fun removeAccelerometerListener(
    listener: OnCarDataAvailableListener<Accelerometer!>
): Unit
```

Remove an ongoing listener for[Accelerometer](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Accelerometer)information.

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

|                                                                                                                               Parameters                                                                                                                                |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|
| `listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Accelerometer](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Accelerometer)`!>` | the listener to remove |

### removeCarHardwareLocationListener

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)  

```
fun removeCarHardwareLocationListener(
    listener: OnCarDataAvailableListener<CarHardwareLocation!>
): Unit
```

Remove an ongoing listener for[CarHardwareLocation](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarHardwareLocation)information.

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

|                                                                                                                                     Parameters                                                                                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|
| `listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[CarHardwareLocation](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/CarHardwareLocation)`!>` | the listener to remove |

### removeCompassListener

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)  

```
fun removeCompassListener(listener: OnCarDataAvailableListener<Compass!>): Unit
```

Remove an ongoing listener for[Compass](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Compass)information.

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

|                                                                                                                         Parameters                                                                                                                          |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|
| `listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Compass](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Compass)`!>` | the listener to remove |

### removeGyroscopeListener

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)  

```
fun removeGyroscopeListener(
    listener: OnCarDataAvailableListener<Gyroscope!>
): Unit
```

Remove an ongoing listener for[Gyroscope](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Gyroscope)information.

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

|                                                                                                                           Parameters                                                                                                                            |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|
| `listener: `[OnCarDataAvailableListener](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/common/OnCarDataAvailableListener)`<`[Gyroscope](https://developer.android.com/reference/kotlin/androidx/car/app/hardware/info/Gyroscope)`!>` | the listener to remove |