# ResolutionStrategy

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

*** ** * ** ***


```
public final class ResolutionStrategy
```

<br />

*** ** * ** ***

The resolution strategy defines the resolution selection sequence to select the best size.

Applications can create a `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionSelector` with a proper ResolutionStrategy to choose the preferred resolution.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_HIGHER() = 2` When the specified bound size is unavailable, CameraX falls back to the closest higher resolution size. |
| `static final int` | `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER() = 1` When the specified bound size is unavailable, CameraX falls back to select the closest higher resolution size. |
| `static final int` | `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_LOWER() = 4` When the specified bound size is unavailable, CameraX falls back to the closest lower resolution size. |
| `static final int` | `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_LOWER_THEN_HIGHER() = 3` When the specified bound size is unavailable, CameraX falls back to select the closest lower resolution size. |
| `static final int` | `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_NONE() = 0` CameraX doesn't select an alternate size when the specified bound size is unavailable. |
| `static final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy` | `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#HIGHEST_AVAILABLE_STRATEGY()` A resolution strategy chooses the highest available resolution. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#ResolutionStrategy(android.util.Size,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/util/Size.html boundSize, int fallbackRule)` Creates a new ResolutionStrategy instance, configured with the specified bound size and fallback rule. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/Size.html` | `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#getBoundSize()()` Returns the specified bound size. |
| `int` | `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#getFallbackRule()()` Returns the fallback rule for choosing an alternate size when the specified bound size is unavailable. |

## Constants

### FALLBACK_RULE_CLOSEST_HIGHER

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

```
public static final int FALLBACK_RULE_CLOSEST_HIGHER = 2
```

When the specified bound size is unavailable, CameraX falls back to the closest higher resolution size.

### FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER

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

```
public static final int FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER = 1
```

When the specified bound size is unavailable, CameraX falls back to select the closest higher resolution size. If CameraX still cannot find any available resolution, it will fallback to select other lower resolutions.

### FALLBACK_RULE_CLOSEST_LOWER

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

```
public static final int FALLBACK_RULE_CLOSEST_LOWER = 4
```

When the specified bound size is unavailable, CameraX falls back to the closest lower resolution size.

### FALLBACK_RULE_CLOSEST_LOWER_THEN_HIGHER

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

```
public static final int FALLBACK_RULE_CLOSEST_LOWER_THEN_HIGHER = 3
```

When the specified bound size is unavailable, CameraX falls back to select the closest lower resolution size. If CameraX still cannot find any available resolution, it will fallback to select other higher resolutions.

### FALLBACK_RULE_NONE

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

```
public static final int FALLBACK_RULE_NONE = 0
```

CameraX doesn't select an alternate size when the specified bound size is unavailable.

Applications will receive `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` when binding the `https://developer.android.com/reference/androidx/camera/core/UseCase`s with this fallback rule if the device doesn't support the specified bound size.

### HIGHEST_AVAILABLE_STRATEGY

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

```
public static final @NonNull ResolutionStrategy HIGHEST_AVAILABLE_STRATEGY
```

A resolution strategy chooses the highest available resolution. This strategy does not have a bound size or fallback rule. When using this strategy, CameraX selects the available resolutions to use in descending order, starting with the highest quality resolution available.

## Public constructors

### ResolutionStrategy

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

```
public ResolutionStrategy(@NonNull Size boundSize, int fallbackRule)
```

Creates a new ResolutionStrategy instance, configured with the specified bound size and fallback rule.

If the resolution candidate list contains the bound size and the bound size can fulfill all resolution selector settings, CameraX can also select the specified bound size as the result for the `https://developer.android.com/reference/androidx/camera/core/UseCase`.

Some devices may have issues using sizes of the preferred aspect ratios. CameraX recommends that applications use the following fallback rule setting to avoid no resolution being available, as an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` may be thrown when calling `https://developer.android.com/reference/androidx/camera/lifecycle/ProcessCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,androidx.camera.core.UseCase...)` to bind `https://developer.android.com/reference/androidx/camera/core/UseCase`s with the ResolutionStrategy specified in the `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionSelector`.

- `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER()`
- `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_LOWER_THEN_HIGHER()`

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/util/Size.html boundSize` | the bound size to select the best resolution with the fallback rule. |
| `int fallbackRule` | the rule to apply when the specified bound size is unavailable. This can be `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER()` or another strategy appropriate for the application. |

## Public methods

### getBoundSize

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

```
public @Nullable Size getBoundSize()
```

Returns the specified bound size.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/Size.html` | the specified bound size or `null` if this is instance of `https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#HIGHEST_AVAILABLE_STRATEGY()`. |

### getFallbackRule

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

```
public int getFallbackRule()
```

Returns the fallback rule for choosing an alternate size when the specified bound size is unavailable.