zxing-android-embedded icon indicating copy to clipboard operation
zxing-android-embedded copied to clipboard

Add a hasTorch() method

Open PaulWoitaschek opened this issue 8 years ago • 0 comments

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()
    }
  }

PaulWoitaschek avatar Jan 14 '17 08:01 PaulWoitaschek