There are some questions in Stackoverflow about this subject, however, none of them solved actually my problem.
I have a helper class where I activate the camera to take a picture. this is the code to call the activity:
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
Image img = new Image();
// crea el archivo en donde se almacenará la foto
File photoFile = null;
try {
photoFile = img.createImageFile(activity.getApplicationContext());
} catch (IOException e) {
Log.e("Photo", e.getMessage());
}
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
activity.startActivityForResult(takePictureIntent, ((FormActivity) activity).REQUEST_TAKE_PHOTO);
}
}
When I take the picture and press "OK" option, I saw that the image is correctly stored in the path (I find it when browsing with the phone file manager). When pressing "OK", the onActivityResult of the activity is actually called, however with null Intent, so I don't know how to get the file name so that I can resize it and then store it in a database.
How can i do it? Thanks
EDIT:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
try {
Bundle extras = data.getExtras();
Uri file = (Uri) extras.get(MediaStore.EXTRA_OUTPUT);
Image img = new Image(file.getPath());
img.resizeImage(200, 200);
//Bitmap imageBitmap = (Bitmap) extras.get("data");
//Image img = new Image();
//mImageView.setImageBitmap(imageBitmap);
}
catch (Exception e)
{
Log.e("TDC@", e.getMessage());
}
}
else
super.onActivityResult(requestCode, resultCode, data);
}