设置参数.FLASH_MODE_TORCH在Droid X 2.3上不工作 [英] Setting Parameters.FLASH_MODE_TORCH doesn't work on Droid X 2.3

查看:476
本文介绍了设置参数.FLASH_MODE_TORCH在Droid X 2.3上不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个应用程序,将闪光灯模式设置为火炬。我一直在测试我的Droid X上的应用程序,并且LED灯不亮。我尝试了一个Droid不可思议,它工作正常。我不知道这是什么问题。这是我打开手电筒模式的代码的一部分。

  Camera mCamera = Camera.open 
Camera.Parameters params = mCamera.getParameters();
if(params.getFlashMode()!= null){
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
}
mCamera.setParameters(params);

我添加了mCamera.startPreview因为我读的应该有区别,但它不。我还制作了一个可用的闪光灯模式列表,并将其显示在屏幕上,以确保我的Droid X有火炬模式,它在列表中。我甚至创建了一个新的应用程序,我发现在线,使用一个按钮打开和关闭LED闪烁。再次,它在Droid Incredible上工作得很好,但不是Droid X.有没有什么我缺少的,以获得这个运行在Droid X,或者它可以是与姜饼的东西?

解决方案

当设置FLASH_MODE_TORCH时,有很多奇怪的地方。 / p>

通常,您需要启动相机预览:

 相机mCamera = Camera.open(); 
mCamera.startPreview();
Camera.Parameters params = mCamera.getParameters();
if(params.getFlashMode()!= null){
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
}
mCamera.setParameters(params);

这可能会解决在某些手机上,其他手机也需要预览绘制到SurfaceView。这可以通过在您的活动中实现SurfaceHolder.Callback接口来实现。
查看示例此处 a>。


I am writing an app that sets the flash mode to torch. I have been testing the application on my Droid X, and the LED light does not come on. I tried it on a Droid Incredible and it worked fine. I can't figure out what the problem is. Here is part of my code for turning on torch mode.

    Camera mCamera = Camera.open();
    Camera.Parameters params = mCamera.getParameters();
    if(params.getFlashMode() != null){
        params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    }
    mCamera.setParameters(params);

I have added mCamera.startPreview(); because I read that should make a difference, but it doesn't. I also made a list of available flash modes and displayed them to the screen to make sure that my Droid X does have torch mode, and it was in the list. I even created a new application from code I found online that turns the LED flash on and off with a button. Again it worked fine on the Droid Incredible but not the Droid X. Is there something I am missing to get this to run on the Droid X, or could it be something with Gingerbread? The Droid X is running Gingerbread and the Droid Incredible is running FroYo.

解决方案

There are quite a few quirks when setting FLASH_MODE_TORCH.

Often you need to start a camera preview:

Camera mCamera = Camera.open();
mCamera.startPreview();
Camera.Parameters params = mCamera.getParameters();
if(params.getFlashMode() != null){
    params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
}
mCamera.setParameters(params);

That may resolve it on some phones, other phones also require the preview to be drawn to a SurfaceView. This can be done by implementing SurfaceHolder.Callback interface in your activity. See an example here.

这篇关于设置参数.FLASH_MODE_TORCH在Droid X 2.3上不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆