Stay organized with collections
Save and categorize content based on your preferences.
SensorEventListener
interface SensorEventListener
Known Direct Subclasses
SensorEventListener2 |
Used for receiving a notification when a flush() has been successfully completed.
|
|
Known Indirect Subclasses
|
Used for receiving notifications from the SensorManager when there is new sensor data.
Summary
Public methods |
abstract Unit |
Called when the accuracy of the registered sensor has changed.
|
abstract Unit |
Called when there is a new sensor event.
|
Public methods
onAccuracyChanged
abstract fun onAccuracyChanged(
sensor: Sensor!,
accuracy: Int
): Unit
Called when the accuracy of the registered sensor has changed. Unlike onSensorChanged(), this is only called when this accuracy value changes.
See the SENSOR_STATUS_* constants in SensorManager
for details.
Parameters |
accuracy |
Int: The new accuracy of this sensor, one of SensorManager.SENSOR_STATUS_* |
onSensorChanged
abstract fun onSensorChanged(event: SensorEvent!): Unit
Called when there is a new sensor event. Note that "on changed" is somewhat of a misnomer, as this will also be called if we have a new reading from a sensor with the exact same sensor values (but a newer timestamp).
See SensorManager
for details on possible sensor types.
See also SensorEvent
.
NOTE: The application doesn't own the event
object passed as a parameter and therefore cannot hold on to it. The object may be part of an internal pool and may be reused by the framework.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# SensorEventListener\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nSensorEventListener\n===================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/hardware/SensorEventListener \"View this page in Java\") \n\n```\ninterface SensorEventListener\n```\n\n|-------------------------------------------|\n| [android.hardware.SensorEventListener](#) |\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [SensorEventListener2](/reference/kotlin/android/hardware/SensorEventListener2) |---------------------------------------------------------------------------------|-----------------------------------------------------------------------------------| | [SensorEventListener2](/reference/kotlin/android/hardware/SensorEventListener2) | Used for receiving a notification when a flush() has been successfully completed. | |\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Indirect Subclasses [SensorEventCallback](/reference/kotlin/android/hardware/SensorEventCallback) |-------------------------------------------------------------------------------|----------------------------------------------------------| | [SensorEventCallback](/reference/kotlin/android/hardware/SensorEventCallback) | Used for receiving sensor additional information frames. | |\n\nUsed for receiving notifications from the SensorManager when there is new sensor data.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onAccuracyChanged](#onAccuracyChanged(android.hardware.Sensor,%20kotlin.Int))`(`sensor:` `[Sensor](/reference/kotlin/android/hardware/Sensor)!`, `accuracy:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Called when the accuracy of the registered sensor has changed. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onSensorChanged](#onSensorChanged(android.hardware.SensorEvent))`(`event:` `[SensorEvent](/reference/kotlin/android/hardware/SensorEvent)!`)` Called when there is a new sensor event. |\n\nPublic methods\n--------------\n\n### onAccuracyChanged\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onAccuracyChanged(\n sensor: Sensor!, \n accuracy: Int\n): Unit\n```\n\nCalled when the accuracy of the registered sensor has changed. Unlike onSensorChanged(), this is only called when this accuracy value changes.\n\nSee the SENSOR_STATUS_\\* constants in [SensorManager](/reference/kotlin/android/hardware/SensorManager) for details.\n\n| Parameters ||\n|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `accuracy` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The new accuracy of this sensor, one of `SensorManager.SENSOR_STATUS_*` |\n\n### onSensorChanged\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onSensorChanged(event: SensorEvent!): Unit\n```\n\nCalled when there is a new sensor event. Note that \"on changed\" is somewhat of a misnomer, as this will also be called if we have a new reading from a sensor with the exact same sensor values (but a newer timestamp).\n\nSee [SensorManager](/reference/kotlin/android/hardware/SensorManager) for details on possible sensor types.\n\nSee also [SensorEvent](/reference/kotlin/android/hardware/SensorEvent).\n\n**NOTE:** The application doesn't own the [event](/reference/kotlin/android/hardware/SensorEvent) object passed as a parameter and therefore cannot hold on to it. The object may be part of an internal pool and may be reused by the framework.\n\n| Parameters ||\n|---------|------------------------------------------------------------------------------------------------------------------------------------|\n| `event` | [SensorEvent](/reference/kotlin/android/hardware/SensorEvent)!: the [SensorEvent](/reference/kotlin/android/hardware/SensorEvent). |"]]