如何检查手电筒是否打开? [英] How to check if the flashlight is on?
问题描述
尝试打开手电筒后,是否有任何方法可以检查?
Is there any way to check once you have tried to turn the flashlight on if it has worked or not?
我正在使用:
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
打开相机电源.该功能适用于大多数手机,但不适用于所有手机,因此我需要知道它是否有效.
To turn the camera on. This works with most phones, but not with all phones so I need to know if it's worked or not.
为清楚起见,我需要知道打开闪光灯是否确实有效.有时您需要使用FLASH_MODE_ON而不是FLASH_MODE_TRUE,有时甚至需要使用FLASH_MODE_ON
Just to be clear, I need to know if turning the flash on has actually worked or not. Sometimes you need to use FLASH_MODE_ON instead of FLASH_MODE_TRUE, and sometimes you need to use FLASH_MODE_ON even when
List<String> flashModes = p.getSupportedFlashModes();
flashModes.contains(Parameters.FLASH_MODE_TORCH)
返回true.
感谢您的帮助.
推荐答案
首先,您需要检查设备是否支持手电筒:
First you need to check if the device supports flashlight:
context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
然后,您可以放心地假定在开始预览时将其打开.
Then you can safely assume that it will be turned on when you start preview.
这篇关于如何检查手电筒是否打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!