# CameraManager.TorchCallback

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

# TorchCallback

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/hardware/camera2/CameraManager.TorchCallback "View this page in Java")  

```
abstract class TorchCallback
```

|---|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                               ||
| ↳ | [android.hardware.camera2.CameraManager.TorchCallback](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager.TorchCallback#) |

A callback for camera flash torch modes becoming unavailable, disabled, or enabled.

The torch mode becomes unavailable when the camera device it belongs to becomes unavailable or other camera resources it needs become busy due to other higher priority camera activities. The torch mode becomes disabled when it was turned off or when the camera device it belongs to is no longer in use and other camera resources it needs are no longer busy. A camera's torch mode is turned off when an application calls[setTorchMode](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#setTorchMode(kotlin.String,%20kotlin.Boolean))to turn off the camera's torch mode, or when an application turns on another camera's torch mode if keeping multiple torch modes on simultaneously is not supported. The torch mode becomes enabled when it is turned on via[setTorchMode](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#setTorchMode(kotlin.String,%20kotlin.Boolean)).

The torch mode is available to set via[setTorchMode](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#setTorchMode(kotlin.String,%20kotlin.Boolean))only when it's in a disabled or enabled state.

Extend this callback and pass an instance of the subclass to android.hardware.camera2.CameraManager#registerTorchCallback to be notified of such status changes.

## Summary

|                                                                Public constructors                                                                 ||
|-------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [TorchCallback](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager.TorchCallback#TorchCallback())`()` <br /> |

|                                                                                                                                                                                                                                                                                                                                                               Public methods                                                                                                                                                                                                                                                                                                                                                                ||
|----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onTorchModeChanged](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager.TorchCallback#onTorchModeChanged(kotlin.String,%20kotlin.Boolean))`(`cameraId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `enabled:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` A camera's torch mode has become enabled or disabled and can be changed via[setTorchMode](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#setTorchMode(kotlin.String,%20kotlin.Boolean)).                                          |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onTorchModeUnavailable](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager.TorchCallback#onTorchModeUnavailable(kotlin.String))`(`cameraId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` A camera's torch mode has become unavailable to set via[setTorchMode](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#setTorchMode(kotlin.String,%20kotlin.Boolean)).                                                                                                                                                                         |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onTorchStrengthLevelChanged](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager.TorchCallback#onTorchStrengthLevelChanged(kotlin.String,%20kotlin.Int))`(`cameraId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `newStrengthLevel:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` A camera's flash unit brightness level has been changed in torch mode via[turnOnTorchWithStrengthLevel](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#turnOnTorchWithStrengthLevel(kotlin.String,%20kotlin.Int)). |

## Public constructors

### TorchCallback

```
TorchCallback()
```

## Public methods

### onTorchModeChanged

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

```
open fun onTorchModeChanged(
    cameraId: String, 
    enabled: Boolean
): Unit
```

A camera's torch mode has become enabled or disabled and can be changed via[setTorchMode](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#setTorchMode(kotlin.String,%20kotlin.Boolean)).

The default implementation of this method does nothing.

|                                                                                                                                                   Parameters                                                                                                                                                    ||
|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `cameraId` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):The unique identifier of the camera whose torch mode has been changed. This value cannot be`null`.                                                                                                                 |
| `enabled`  | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):The state that the torch mode of the camera has been changed to.`true`when the torch mode has become on and available to be turned off.`false`when the torch mode has becomes off and available to be turned on. |

### onTorchModeUnavailable

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

```
open fun onTorchModeUnavailable(cameraId: String): Unit
```

A camera's torch mode has become unavailable to set via[setTorchMode](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#setTorchMode(kotlin.String,%20kotlin.Boolean)).

If torch mode was previously turned on by calling[setTorchMode](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#setTorchMode(kotlin.String,%20kotlin.Boolean)), it will be turned off before[CameraManager.TorchCallback.onTorchModeUnavailable](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager.TorchCallback#onTorchModeUnavailable(kotlin.String))is invoked.[setTorchMode](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#setTorchMode(kotlin.String,%20kotlin.Boolean))will fail until the torch mode has entered a disabled or enabled state again.

The default implementation of this method does nothing.

|                                                                                              Parameters                                                                                               ||
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `cameraId` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):The unique identifier of the camera whose torch mode has become unavailable. This value cannot be`null`. |

### onTorchStrengthLevelChanged

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

```
open fun onTorchStrengthLevelChanged(
    cameraId: String, 
    newStrengthLevel: Int
): Unit
```

A camera's flash unit brightness level has been changed in torch mode via[turnOnTorchWithStrengthLevel](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraManager#turnOnTorchWithStrengthLevel(kotlin.String,%20kotlin.Int)). When the torch is turned OFF, this callback will not be triggered even though the torch strength level resets to default value[android.hardware.camera2.CameraCharacteristics#FLASH_INFO_STRENGTH_DEFAULT_LEVEL](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#FLASH_INFO_STRENGTH_DEFAULT_LEVEL:android.hardware.camera2.CameraCharacteristics.Key)

The default implementation of this method does nothing.

|                                                                                                        Parameters                                                                                                        ||
|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `cameraId`         | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):The unique identifier of the camera whose flash unit brightness level has been changed. This value cannot be`null`. |
| `newStrengthLevel` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The brightness level of the flash unit that has been changed to.                                                          |