我在程序中使用相機閃光燈,使用代碼實現,開燈和關燈功能可以實現,但是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) {
}
});
}
代碼錯了
/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);