Android 相机 LED 灯在 2 秒后熄灭?
我在我的应用程序中使用相机闪光灯,我已经完成了编码,它正在打开/关闭灯。 但 2 秒后它就会关闭。如果我再次按下打开按钮,它就会强制关闭。 这是我正在使用的代码,请帮助我。
我想要这样,如果用户按下打开按钮灯亮起,直到用户按下关闭按钮。
private void processOffClick() {
//togglebutton.setButtonDrawable(R.drawable.offbutton);
System.out.println("in off state");
if( cam != null ){
cam.stopPreview();
cam.release();
}
}
private void processOnClick() {
//togglebutton.setButtonDrawable(R.drawable.onbutton);
System.out.println("in on state");
cam = Camera.open();
Parameters params = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_ON);
cam.setParameters(params);
cam.startPreview();
cam.autoFocus(new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
}
});
}
I am using the camera flash light in my application, I was done coding for that, it's working on/off the light.
but after 2 seconds it goes to off. If I press the on button again it was giving force close.
This is the code i am using for this, please help me.
I want this like if user presses the on button light On, upto user press Off button.
private void processOffClick() {
//togglebutton.setButtonDrawable(R.drawable.offbutton);
System.out.println("in off state");
if( cam != null ){
cam.stopPreview();
cam.release();
}
}
private void processOnClick() {
//togglebutton.setButtonDrawable(R.drawable.onbutton);
System.out.println("in on state");
cam = Camera.open();
Parameters params = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_ON);
cam.setParameters(params);
cam.startPreview();
cam.autoFocus(new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将以下行:
放在 processOffClick 中,而不是将其放在 processOnClick 中
像这样:
它可能会起作用,我没有检查代码
,我添加了一个 while 循环,这样它就会保持闪光灯和焦点,直到它未被点击。
put the lines:
in processOffClick instead of putting it in processOnClick
like that:
It might work, i didn't check the code
I added a while loop so it would hold the flash and the focus until its unclicked.
我的经验表明,闪光模式应该是“TORCH”(如果支持),并且仅当您开始预览时才会启动。然而,相机在不同设备上的表现非常不同,并不总是像其功能描述中所宣传的那样
My experience says, that flash mode ought to be "TORCH" ( if supported ) and it is started only when you start preview. However, cameras behave very differently on different devices and not always as advertised in their capabilities descrioptors
1.打开
2.关闭
然后,在 AndroidManifest.xml 上添加以下权限。
看到这个 http://www.mkyong .com/android/how-to-turn-onoff-camera-ledflashlight-in-android/
1.Turn on
2. Turn off
And, put following permission on AndroidManifest.xml.
see this one http://www.mkyong.com/android/how-to-turn-onoff-camera-ledflashlight-in-android/