设置Parameters.FLASH_MODE_TORCH在Droid X 2.3上不起作用
我正在编写一个将闪光灯模式设置为手电筒的应用程序。我一直在我的 Droid X 上测试该应用程序,但 LED 灯不亮。我在 Droid Incredible 上尝试过,效果很好。我不知道问题出在哪里。这是我打开火炬模式的代码的一部分。
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 上运行,或者可能是 Gingerbread 上的东西? Droid X 正在运行 Gingerbread,而 Droid Incredible 正在运行 FroYo。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Droid X 可能不支持手电筒模式。尝试这样的事情:
It could be that the Droid X doesn't support Torch Mode. Try something like this:
请参阅问题 191453:
Refer to Issue 191453:
我发现唯一可以在 Droid X 上运行的是 Siddhpura Amit 在这个答案中页面下方提供的代码 在 Android 中使用相机手电筒。他检查了制造商并检查它是否包含字符串“motorola”。如果是这样,他有特殊的代码可以打开或关闭相机闪光灯 LED。我可以验证它是否有效,因为我有一台 Motorola Droid X。
The only thing I found that works on the Droid X is the code presented by Siddhpura Amit part way down the page in this answer Use camera flashlight in Android. He checks the manufacturer and checks to see if it contains the string "motorola." If so, he has special code that can switch the camera Flash LED on or off. I can verify that it does work as I have a Motorola Droid X.
设置 FLASH_MODE_TORCH 时有很多怪癖。
通常,您需要启动相机预览:
这可能会在某些手机上解决此问题,其他手机还需要将预览绘制到 SurfaceView。这可以通过在您的活动中实现 SurfaceHolder.Callback 接口来完成。
请参阅此处< /a>.
There are quite a few quirks when setting FLASH_MODE_TORCH.
Often you need to start a camera preview:
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.