Stay organized with collections
Save and categorize content based on your preferences.
OrientationEventListener
abstract class OrientationEventListener
Helper class for receiving notifications from the SensorManager when the orientation of the device has changed.
Summary
Constants |
static Int |
Returned from onOrientationChanged when the device orientation cannot be determined (typically when the device is in a close to flat position).
|
Public constructors |
Creates a new OrientationEventListener.
|
Creates a new OrientationEventListener.
|
Public methods |
open Boolean |
|
open Unit |
Disables the OrientationEventListener.
|
open Unit |
Enables the OrientationEventListener so it will monitor the sensor and call onOrientationChanged when the device orientation changes.
|
abstract Unit |
Called when the orientation of the device has changed.
|
Constants
ORIENTATION_UNKNOWN
static val ORIENTATION_UNKNOWN: Int
Returned from onOrientationChanged when the device orientation cannot be determined (typically when the device is in a close to flat position).
Value: -1
Public constructors
OrientationEventListener
OrientationEventListener(context: Context!)
Creates a new OrientationEventListener.
Parameters |
context |
Context!: for the OrientationEventListener. |
OrientationEventListener
OrientationEventListener(
context: Context!,
rate: Int)
Creates a new OrientationEventListener.
Parameters |
context |
Context!: for the OrientationEventListener. |
rate |
Int: at which sensor events are processed (see also SensorManager ). Use the default value of SENSOR_DELAY_NORMAL for simple screen orientation change detection. |
Public methods
canDetectOrientation
open fun canDetectOrientation(): Boolean
disable
open fun disable(): Unit
Disables the OrientationEventListener.
enable
open fun enable(): Unit
Enables the OrientationEventListener so it will monitor the sensor and call onOrientationChanged
when the device orientation changes.
onOrientationChanged
abstract fun onOrientationChanged(orientation: Int): Unit
Called when the orientation of the device has changed. orientation parameter is in degrees, ranging from 0 to 359. orientation is 0 degrees when the device is oriented in its natural position, 90 degrees when its left side is at the top, 180 degrees when it is upside down, and 270 degrees when its right side is to the top. ORIENTATION_UNKNOWN
is returned when the device is close to flat and the orientation cannot be determined.
Parameters |
orientation |
Int: The new orientation of the device. |
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,["# OrientationEventListener\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nOrientationEventListener\n========================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/view/OrientationEventListener \"View this page in Java\") \n\n```\nabstract class OrientationEventListener\n```\n\n|---|--------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.view.OrientationEventListener](#) |\n\nHelper class for receiving notifications from the SensorManager when the orientation of the device has changed.\n\nSummary\n-------\n\n| Constants ||\n|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ORIENTATION_UNKNOWN](#ORIENTATION_UNKNOWN:kotlin.Int) Returned from onOrientationChanged when the device orientation cannot be determined (typically when the device is in a close to flat position). |\n\n| Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [OrientationEventListener](#OrientationEventListener(android.content.Context))`(`context:` `[Context](../content/Context.html#)!`)` Creates a new OrientationEventListener. |\n| [OrientationEventListener](#OrientationEventListener(android.content.Context,%20kotlin.Int))`(`context:` `[Context](../content/Context.html#)!`, `rate:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Creates a new OrientationEventListener. |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [canDetectOrientation](#canDetectOrientation())`()` \u003cbr /\u003e |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [disable](#disable())`()` Disables the OrientationEventListener. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [enable](#enable())`()` Enables the OrientationEventListener so it will monitor the sensor and call [onOrientationChanged](#onOrientationChanged(kotlin.Int)) when the device orientation changes. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onOrientationChanged](#onOrientationChanged(kotlin.Int))`(`orientation:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Called when the orientation of the device has changed. |\n\nConstants\n---------\n\n### ORIENTATION_UNKNOWN\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nstatic val ORIENTATION_UNKNOWN: Int\n```\n\nReturned from onOrientationChanged when the device orientation cannot be determined (typically when the device is in a close to flat position). \n\n Value: -1\n\n**See Also**\n\n- [#onOrientationChanged](#onOrientationChanged(kotlin.Int))\n\nPublic constructors\n-------------------\n\n### OrientationEventListener\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nOrientationEventListener(context: Context!)\n```\n\nCreates a new OrientationEventListener.\n\n| Parameters ||\n|-----------|-------------------------------------------------------------------------|\n| `context` | [Context](../content/Context.html#)!: for the OrientationEventListener. |\n\n### OrientationEventListener\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nOrientationEventListener(\n context: Context!, \n rate: Int)\n```\n\nCreates a new OrientationEventListener.\n\n| Parameters ||\n|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `context` | [Context](../content/Context.html#)!: for the OrientationEventListener. |\n| `rate` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): at which sensor events are processed (see also [SensorManager](../hardware/SensorManager.html#)). Use the default value of [SENSOR_DELAY_NORMAL](../hardware/SensorManager.html#SENSOR_DELAY_NORMAL:kotlin.Int) for simple screen orientation change detection. |\n\nPublic methods\n--------------\n\n### canDetectOrientation\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun canDetectOrientation(): Boolean\n``` \n\n### disable\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun disable(): Unit\n```\n\nDisables the OrientationEventListener. \n\n### enable\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun enable(): Unit\n```\n\nEnables the OrientationEventListener so it will monitor the sensor and call [onOrientationChanged](#onOrientationChanged(kotlin.Int)) when the device orientation changes. \n\n### onOrientationChanged\n\nAdded in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onOrientationChanged(orientation: Int): Unit\n```\n\nCalled when the orientation of the device has changed. orientation parameter is in degrees, ranging from 0 to 359. orientation is 0 degrees when the device is oriented in its natural position, 90 degrees when its left side is at the top, 180 degrees when it is upside down, and 270 degrees when its right side is to the top. [ORIENTATION_UNKNOWN](#ORIENTATION_UNKNOWN:kotlin.Int) is returned when the device is close to flat and the orientation cannot be determined.\n\n| Parameters ||\n|---------------|----------------------------------------------------------------------------------------------------------------|\n| `orientation` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The new orientation of the device. |\n\n**See Also**\n\n- [#ORIENTATION_UNKNOWN](#ORIENTATION_UNKNOWN:kotlin.Int)"]]