# ImageCapture.ScreenFlash

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/ImageCapture.java+class:androidx.camera.core.ImageCapture.ScreenFlash) Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/camera#1.4.0)

*** ** * ** ***


```
public interface ImageCapture.ScreenFlash
```

<br />

*** ** * ** ***

Interface to do the application changes required for screen flash operations.

Each `https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlash#apply(long,androidx.camera.core.ImageCapture.ScreenFlashListener)` invocation will be followed up with a corresponding `https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlash#clear()` invocation. For each image capture, `#apply` and `#clear` will be invoked only once.

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/UiThread https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlash#apply(long,androidx.camera.core.ImageCapture.ScreenFlashListener)( long expirationTimeMillis, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlashListener screenFlashListener )` Applies the necessary application changes for a screen flash photo capture. |
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/UiThread https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlash#clear()()` Clears any application change done for screen flash operation, if required. |

## Public methods

### apply

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

```
@UiThread
abstract void apply(
    long expirationTimeMillis,
    @NonNull ImageCapture.ScreenFlashListener screenFlashListener
)
```

Applies the necessary application changes for a screen flash photo capture.

When the application UI needs to be changed for a successful photo capture with screen flash feature, CameraX will invoke this method and wait for the application to complete its changes. When this API is invoked, the application UI should utilize the screen to provide extra light as an alternative to physical flash. For example, the screen brightness can be maximized and screen color can be covered with some bright color like white.

The parameter `expirationTimeMillis` is based on `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()`. It is at least 3 seconds later from the start of a screen flash image capture operation. Until the timestamp of `expirationTimeMillis` parameter, CameraX will wait for the application to notify the completion of the application-side changes using the `https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlashListener` parameter of this method. Applications must call `https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlashListener#onCompleted()` after their UI changes are done so that CameraX is not unnecessarily waiting. If the application does not call `ScreenFlashListener#onCompleted` before `
expirationTimeMillis`, CameraX will stop waiting and move forward with the subsequent operations regardless. In such case, the application no longer needs to call `
ScreenFlashListener#onCompleted()`. If `https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlash#clear()` has also been invoked while the application is still doing the changes, it is the application's responsibility to clear any UI change done after `https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlash#clear()` has been invoked.

The following code snippet shows an example implementation of this API.

```
public void apply(long expirationTimeMillis,
        ScreenFlashListener screenFlashListener) {
    // Enable top overlay to make screen color white
    whiteColorOverlay.setVisible(true);
    // Maximize screen brightness
    maximizeScreenBrightness();
    screenFlashListener.onCompleted();
}
```

| Parameters |
|---|---|
| `long expirationTimeMillis` | The timestamp after which CameraX will no longer listen to `screenFlashListener`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageCapture.ScreenFlashListener screenFlashListener` | Used to notify when UI changes have been applied. |

### clear

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

```
@UiThread
abstract void clear()
```

Clears any application change done for screen flash operation, if required.

CameraX will invoke this method when a screen flash photo capture has been completed and the application screen can be safely changed to a state not conforming to screen flash photo capture.