Reputation: 406
I am developing an app for a Bluetooth device in which I have to take a picture on Bluetooth button click.
I have coded for the receiver of BLE device and I get the button clicked event in receiver, But main problem is capture image code does not work.
I have tried following code in receiver
Intent intent1 = new Intent("android.intent.action.CAMERA_BUTTON");
intent1.putExtra("android.intent.extra.KEY_EVENT", new KeyEvent(0, KeyEvent.KEYCODE_CAMERA));
sendOrderedBroadcast(intent1, null);
intent1 = new Intent("android.intent.action.CAMERA_BUTTON");
intent1.putExtra("android.intent.extra.KEY_EVENT", new KeyEvent(1, KeyEvent.KEYCODE_CAMERA));
sendOrderedBroadcast(intent1, null);
I have also tried changing KEYCODE_CAMERA
to KEYCODE_VOLUME_UP
but this too do not work.
What do I code to get camera capture button event?
Upvotes: 1
Views: 2743
Reputation: 532
you should try doing like this.
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_DOWN) {
//TODO
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
//TODO
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
or You can take reference from http://www.androidhive.info/2013/09/android-working-with-camera-api/
Upvotes: 1
Reputation: 6978
Refer official documentation to develop a camera app.
Refer sub section Capturing pictures
which suggests to use Camera.takePicture() method to capture image.
Upvotes: 0