Probably 90% of the time, the callbacks will fail to trigger. And hence my picture is never saved.
What am I doing wrong?
@Override
public boolean onTouchEvent(MotionEvent event)
{
boolean result = super.onTouchEvent(event);
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN)
{
takePicture();
this.finish(); // ERROR IS HERE. Closing down before callback is done.
}
return result;
}
private void takePicture() {
if (mCamera != null)
mCamera.takePicture(shutterCallback, null, jpegCallback);
}
ShutterCallback shutterCallback = new ShutterCallback() {
public void onShutter() {
AudioManager meng = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
int volume = meng.getStreamVolume( AudioManager.STREAM_NOTIFICATION);
if (volume != 0)
{
MediaPlayer _shootMP = MediaPlayer.create(getBaseContext(), Uri.parse("file:///system/media/audio/ui/camera_click.ogg"));
_shootMP.start();
}
Toast.makeText(CameraActivity.this, "Picture Taken", Toast.LENGTH_SHORT).show();
}
};
PictureCallback rawCallback = new PictureCallback() {
public void onPictureTaken(byte[] _data, Camera _camera) {
// TODO Do something with the image RAW data.
int test = 1;
}
};
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] _data, Camera _camera) {
File photo=new File(Environment.getExternalStorageDirectory(), "photo1.jpg");
if (photo.exists()) {
photo.delete();
}
try {
FileOutputStream fos=new FileOutputStream(photo.getPath());
fos.write(_data);
fos.close();
}
catch (java.io.IOException e) {
Log.e("PictureDemo", "Exception in photoCallback", e);
}
SqlDB.SavePhoto(1, _data);
}
};
Can you debug and check is it going in any of the function rawCallback or jpegCallback. You are setting jpeg format for your camera or not. I think according to that callback function will be called. So it should either go in rawCallback or jpegCallback. Can you try once.
mCamera.takePicture(shutterCallback, rawCallback , jpegCallback);
if it is failing then where it is going may be somewhere you are opening your camera again. In this case i think your camera parameter will be reset and may return raw callback instead of jpeg
Actually I think if camera is not crashing and it is not null then is the only case remains is you are resetting your camera with default settings or you are opening your camera again..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With