# 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)

*** ** * ** ***


```
public final 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/androidx/camera/core/UseCase` target rotation based on the device's physical rotation.

```
// 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 |
|---|
| `public interface https://developer.android.com/reference/androidx/camera/view/RotationProvider.Listener` Callback interface to receive rotation updates. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/view/RotationProvider#RotationProvider(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Creates a new RotationProvider. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/camera/view/RotationProvider#addListener(java.util.concurrent.Executor,androidx.camera.view.RotationProvider.Listener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/view/RotationProvider.Listener listener )` Sets a `https://developer.android.com/reference/androidx/camera/view/RotationProvider.Listener` that listens for rotation changes. |
| `void` | `https://developer.android.com/reference/androidx/camera/view/RotationProvider#removeListener(androidx.camera.view.RotationProvider.Listener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/view/RotationProvider.Listener listener)` Removes the given `https://developer.android.com/reference/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)

```
public RotationProvider(@NonNull Context context)
```

Creates a new RotationProvider.

## Public methods

### addListener

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

```
public boolean addListener(
    @NonNull Executor executor,
    @NonNull RotationProvider.Listener listener
)
```

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The executor in which the `https://developer.android.com/reference/androidx/camera/view/RotationProvider.Listener#onRotationChanged(int)` |

### removeListener

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

```
public void removeListener(@NonNull RotationProvider.Listener listener)
```

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

The removed listener will no longer receive rotation updates.