I'm trying to capture a photo using the MediaStore.ACTION_IMAGE_CAPTURE intent but I'm having some issues with getting it to do what I want. I've got the camera launching, and I can take a picture with it, but I have a few different actions I need to perform depending on what buttons are pushed at what stage.
Basically:
- If on the camera intent and you press the Back button, exit to an activity class
- After taking a picture, if you press Discard, go back to camera intent
- After taking a picture, if you press Save, go back to camera intent
In my activity I've got a method that I call from my onCreate method:
private void dispatchTakePictureIntent() {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (i.resolveActivity(getPackageManager()) != null) {
startActivityForResult(i, REQUEST_IMAGE_CAPTURE);
}
}
That seems to be working fine. The issues I'm running into have to do with my onActivityResult method.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap image = (Bitmap )extras.get("data");
// Here is where I'm stuck. The docs I've found
// are saying this is only a thumbnail.
// I need to get it as a byte array, I think.
dispatchTakePictureIntent(); // I'm getting camera intents stacking
// on top of each other from this
// I think there's a way to close them
// after launching a new one
}
// Here is where I think I need to put the if statement
// to handle the Discard resultCode
}
// I'm trying to save the photos and upload them to parse
private void savePhoto(byte[] data) {
parseFile = new ParseFile(ParseUser.getCurrentUser().getUsername()
+ System.currentTimeMillis() + .jpg", data);
// Some other parse methods
parseFile.saveInBackground(new SaveCallBack() {
// More parse stuff
});
}
This is my first time ever working with the camera so I've been reading the android docs, but I can't find much that has helped.