您好我想在android系統實現火炬的應用所以這裏是我的代碼火炬應用軟件Android
setContentView(R.layout.main);
camera = Camera.open();
if(camera == null)
Toast.makeText(getBaseContext(),"CAMERA FAILED", Toast.LENGTH_LONG).show();
else
Toast.makeText(getBaseContext(),"camera opened",Toast.LENGTH_LONG).show();
}
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) {
if(camera!=null)
{
Toast.makeText(getBaseContext(),"came to volume up",Toast.LENGTH_LONG).show();
Parameters params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_ON);
camera.setParameters(params);
}
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_UP) {
Parameters params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.release();
camera = null;
Toast.makeText(getBaseContext(),"came to volume down",Toast.LENGTH_LONG).show();
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
}
爲什麼這個代碼不工作???
您是否收到任何錯誤訊息? – 2011-04-19 11:01:10
不,我還沒有得到任何錯誤信息......它也會發生事件,但問題是我不能使用我的代碼閃光燈和關閉 – Durga 2011-04-19 11:02:30
什麼是不工作。它拋出一個錯誤?它是否進入Key Event偵聽器?你在那裏有很多房地產,這將有助於隔離真正出問題的地方。 – Brian 2011-04-19 11:02:30