我使用的是相机的闪光灯在我的申请,我做编码为,它的工作开/关灯。但在2秒钟后它去了。如果我按钮preSS再次它被赋予强制关闭。这是code我用这个,请帮助我。
我想这就像如果用户presses的按钮指示灯亮起,用户高达preSS关按钮。
私人无效processOffClick(){ //togglebutton.setButtonDrawable(R.drawable.offbutton); 的System.out.println(关机状态); 如果(凸轮!= NULL){ cam.stop preVIEW(); cam.release(); }}私人无效processOnClick(){ //togglebutton.setButtonDrawable(R.drawable.onbutton); 的System.out.println(在国家); 凸轮= Camera.open(); 参数PARAMS = cam.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_ON); cam.setParameters(PARAMS); cam.start preVIEW(); cam.autoFocus(新AutoFocusCallback(){ 公共无效onAutoFocus(布尔成功,相机摄像头){ } });}
解决方案
把行:
参数PARAMS = cam.getParameters();params.setFlashMode(Parameters.FLASH_MODE_ON);cam.setParameters(PARAMS);
的在processOffClick,而不是把它processOnClick这样的:
布尔点击= FALSE;私人无效processOffClick(){ //togglebutton.setButtonDrawable(R.drawable.offbutton); 点击= FALSE; 的System.out.println(关机状态); 如果(凸轮!= NULL){ cam.stop preVIEW(); cam.release(); }}私人无效processOnClick(){ 点击= TRUE; //togglebutton.setButtonDrawable(R.drawable.onbutton); 的System.out.println(在国家); 凸轮= Camera.open(); 参数PARAMS = cam.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_ON); 而(点击){ cam.setParameters(PARAMS); cam.start preVIEW(); cam.autoFocus(新AutoFocusCallback(){ 公共无效onAutoFocus(布尔成功,相机摄像头){ } }); }}
这可能会工作,我没有检查code
我添加了一个while循环,以便将举行闪光灯和对焦直到未点击。
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) {
}
});
}
解决方案
put the lines:
Parameters params = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_ON);
cam.setParameters(params);
in processOffClick instead of putting it in processOnClick like that:
boolean clicked = false;
private void processOffClick() {
//togglebutton.setButtonDrawable(R.drawable.offbutton);
clicked = false;
System.out.println("in off state");
if( cam != null ){
cam.stopPreview();
cam.release();
}
}
private void processOnClick() {
clicked = true;
//togglebutton.setButtonDrawable(R.drawable.onbutton);
System.out.println("in on state");
cam = Camera.open();
Parameters params = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_ON);
while(clicked) {
cam.setParameters(params);
cam.startPreview();
cam.autoFocus(new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
}
});
}
}
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.