# OrientationEventListener

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Constants](https://developer.android.com/reference/android/view/OrientationEventListener#constants)\|[Ctors](https://developer.android.com/reference/android/view/OrientationEventListener#pubctors)\|[Methods](https://developer.android.com/reference/android/view/OrientationEventListener#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/view/OrientationEventListener#inhmethods)  

# OrientationEventListener

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/view/OrientationEventListener "View this page in Kotlin")\|Java

`
public


abstract
class
OrientationEventListener
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|---------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.OrientationEventListener |

<br />

*** ** * ** ***

Helper class for receiving notifications from the SensorManager when the orientation of the device has changed.

## Summary

|                                                                                                                                  ### Constants                                                                                                                                  ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [ORIENTATION_UNKNOWN](https://developer.android.com/reference/android/view/OrientationEventListener#ORIENTATION_UNKNOWN) Returned from onOrientationChanged when the device orientation cannot be determined (typically when the device is in a close to flat position). |

|                                                                                                                                               ### Public constructors                                                                                                                                               ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[OrientationEventListener](https://developer.android.com/reference/android/view/OrientationEventListener#OrientationEventListener(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) ` Creates a new OrientationEventListener.                  |
| ` `[OrientationEventListener](https://developer.android.com/reference/android/view/OrientationEventListener#OrientationEventListener(android.content.Context,%20int))`(`[Context](https://developer.android.com/reference/android/content/Context)` context, int rate) ` Creates a new OrientationEventListener. |

|                                                                                                                                                                               ### Public methods                                                                                                                                                                               ||
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`       | ` `[canDetectOrientation](https://developer.android.com/reference/android/view/OrientationEventListener#canDetectOrientation())`() `                                                                                                                                                                                                                         |
| ` void`          | ` `[disable](https://developer.android.com/reference/android/view/OrientationEventListener#disable())`() ` Disables the OrientationEventListener.                                                                                                                                                                                                            |
| ` void`          | ` `[enable](https://developer.android.com/reference/android/view/OrientationEventListener#enable())`() ` Enables the OrientationEventListener so it will monitor the sensor and call[onOrientationChanged(int)](https://developer.android.com/reference/android/view/OrientationEventListener#onOrientationChanged(int))when the device orientation changes. |
| ` abstract void` | ` `[onOrientationChanged](https://developer.android.com/reference/android/view/OrientationEventListener#onOrientationChanged(int))`(int orientation) ` Called when the orientation of the device has changed.                                                                                                                                                |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Constants

### ORIENTATION_UNKNOWN

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int ORIENTATION_UNKNOWN
```

Returned from onOrientationChanged when the device orientation cannot be determined (typically when the device is in a close to flat position).

<br />

**See also:**

- [onOrientationChanged(int)](https://developer.android.com/reference/android/view/OrientationEventListener#onOrientationChanged(int))

Constant Value: -1 (0xffffffff)

## Public constructors

### OrientationEventListener

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public OrientationEventListener (Context context)
```

Creates a new OrientationEventListener.

<br />

|                           Parameters                           ||
|-----------|-----------------------------------------------------|
| `context` | `Context`: for the OrientationEventListener. <br /> |

### OrientationEventListener

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public OrientationEventListener (Context context, 
                int rate)
```

Creates a new OrientationEventListener.

<br />

|                                                                                                                                                                        Parameters                                                                                                                                                                         ||
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context` | `Context`: for the OrientationEventListener. <br />                                                                                                                                                                                                                                                                                            |
| `rate`    | `int`: at which sensor events are processed (see also[SensorManager](https://developer.android.com/reference/android/hardware/SensorManager)). Use the default value of[SENSOR_DELAY_NORMAL](https://developer.android.com/reference/android/hardware/SensorManager#SENSOR_DELAY_NORMAL)for simple screen orientation change detection. <br /> |

## Public methods

### canDetectOrientation

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean canDetectOrientation ()
```

<br />

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### disable

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void disable ()
```

Disables the OrientationEventListener.

<br />

### enable

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void enable ()
```

Enables the OrientationEventListener so it will monitor the sensor and call[onOrientationChanged(int)](https://developer.android.com/reference/android/view/OrientationEventListener#onOrientationChanged(int))when the device orientation changes.

<br />

### onOrientationChanged

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void onOrientationChanged (int orientation)
```

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](https://developer.android.com/reference/android/view/OrientationEventListener#ORIENTATION_UNKNOWN)is returned when the device is close to flat and the orientation cannot be determined.

<br />

|                           Parameters                            ||
|---------------|--------------------------------------------------|
| `orientation` | `int`: The new orientation of the device. <br /> |

**See also:**

- [ORIENTATION_UNKNOWN](https://developer.android.com/reference/android/view/OrientationEventListener#ORIENTATION_UNKNOWN)