# RotationProvider

Artifact: [androidx.camera:camera-view](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/view/RotationProvider.java+class:androidx.camera.view.RotationProvider) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

*** ** * ** ***


```
class RotationProvider
```

<br />

*** ** * ** ***

Provider for receiving rotation updates from the `https://developer.android.com/reference/android/hardware/SensorManager.html` when the rotation of the device has changed.

This class monitors motion sensor and notifies the listener about physical orientation changes in the format of `https://developer.android.com/reference/android/view/Surface.html` rotation. It's useful when the `https://developer.android.com/reference/android/app/Activity.html` is in a fixed portrait or landscape orientation, while the app still wants to set the `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` target rotation based on the device's physical rotation.

```kotlin
// Create a provider.
RotationProvider mRotationProvider = new RotationProvider(getContext());

// Add listener to receive updates.
mRotationProvider.addListener(rotation -> {
    mImageCapture.setTargetRotation(rotation);
});

// Remove when no longer needed.
mRotationProvider.removeListener(listener);
```

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider.Listener` Callback interface to receive rotation updates. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider#RotationProvider(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Creates a new RotationProvider. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider#addListener(java.util.concurrent.Executor,androidx.camera.view.RotationProvider.Listener)(executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, listener: https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider.Listener)` Sets a `https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider.Listener` that listens for rotation changes. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider#removeListener(androidx.camera.view.RotationProvider.Listener)(listener: https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider.Listener)` Removes the given `https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider.Listener` from this object. |

## Public constructors

### RotationProvider

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

```
RotationProvider(context: Context)
```

Creates a new RotationProvider.

## Public functions

### addListener

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

```
fun addListener(executor: Executor, listener: RotationProvider.Listener): Boolean
```

Sets a `https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider.Listener` that listens for rotation changes.

| Parameters |
|---|---|
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The executor in which the `https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider.Listener#onRotationChanged(int)` |

### removeListener

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

```
fun removeListener(listener: RotationProvider.Listener): Unit
```

Removes the given `https://developer.android.com/reference/kotlin/androidx/camera/view/RotationProvider.Listener` from this object.

The removed listener will no longer receive rotation updates.