I have a Droid X, which has a physical camera button. I am using the example used here: http://marakana.com/forums/android/examples/39.html
The app sort-of works. The on-screen button captures and displays the preview image. But if I push the physical camera button, the app crashes.
How should I handle this, and more importantly - is this going to cause problems across different devices that do / do not have physical buttons?
You need to override onKeyDown
in your Activity
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN)
{
switch(keyCode)
{
case KeyEvent.KEYCODE_CAMERA:
// handle the event here
}
}
return super.onKeyDown(keyCode, event);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.