zxing-android-embedded
zxing-android-embedded copied to clipboard
Add a hasTorch() method
It would be great to have a method that returns if the device has a torch. Alternatively the camera could be exposed.
Currently I have to open a camera manually, get the info and release it. But thats pain and forces me to use a handler for calls made later to ensure the camera is available again.
fun hasTorch(): Boolean {
val camera = try {
OpenCameraInterface.open(OpenCameraInterface.NO_REQUESTED_CAMERA)
} catch (ignored: Exception) {
Timber.e("no camera")
return false
}
val supportedFlashModes: List<String>? = camera.parameters.supportedFlashModes
try {
@Suppress("DEPRECATION")
return supportedFlashModes != null && supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)
} finally {
camera.release()
}
}