如果前置摄像头支持闪光灯的Android测试 [英] Android test if front camera supports flash
问题描述
我所知道的是可以检测,如果相机闪光灯集成,使用这样的方法:
I know is possible to detect if camera has flash integrated, using a method like this:
/**
* @return true if a flash is available, false if not
*/
public static boolean isFlashAvailable(Context context) {
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
}
但如果设备有2个摄像头我怎么能为他们每个人的测试,如果有可用的闪光灯?
but if the device has 2 cameras how can I test for each of them if has flash available?
例如三星S2的设备上,原生相机应用程序时,使用前置摄像头闪光灯按钮是无效的,含义是不具备的。
For example on a Samsung S2 device, on native camera application when using the front camera the flash button is disabled, meaning is not available.
感谢。
推荐答案
保罗的回答并没有为我工作。在Galaxy Nexus的前置摄像头有 FLASH_MODE_OFF
的有效闪光模式,但它是唯一支持的选项。此方法适用于所有情况:
Paul's answer didn't work for me. The front camera on a Galaxy Nexus has a valid flash-mode of FLASH_MODE_OFF
, but it is the only supported option. This method will work in all situations:
private boolean hasFlash(){
Parameters params = mCamera.getParameters();
List<String> flashModes = params.getSupportedFlashModes();
if(flashModes == null) {
return false;
}
for(String flashMode : flashModes) {
if(Parameters.FLASH_MODE_ON.equals(flashMode)) {
return true;
}
}
return false;
}
如果您的应用程序支持的不仅仅是 FLASH_MODE_OFF
和 FLASH_MODE_ON
,你就需要调整,如果检查内循环。
If your app supports more than just FLASH_MODE_OFF
and FLASH_MODE_ON
, you'll need to tweak the if-check inside the loop.
这篇关于如果前置摄像头支持闪光灯的Android测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!