Hi, I'm writing an application that uses Intent(MediaStore.ACTION_IMAGE_CAPTURE) to capture and image. On the process of capturing the image, I noted the output of the image's URI. Right after finishing the camera activity, I wish to display the image using this specific URI.
The method I used to capture images is:
private void saveFullImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
"test.jpg");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
Which is a method taken from Reto Meier's book Professional Android 2 Application Development.
The method works fine, and I assume that the URI of the picture I just took is stored in the outputFileUri variable. Then at this point of the code is where I want to display the picture:
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE) {
//I want to display the picture I just took here
//using the URI
}
}
I'm not sure how to do it.
I tried creating a new layout object and a new ImageView object using the method setImageURI(outputFileUri). My main layout (xml) did not have a ImageView object. But even when I set the contentView to the new layout with the ImageView attached to it, it doesn't display anything. I tried creating a Bitmap object from the URI and set it to the ImageView, but I get an unexpected error and forced exit.
I have seen examples from here here which creates a Bitmap from URI, but it's not displaying it?
My question is just how to display an image in the middle of a running activity? Do I need to get the File Path (like this) in order to display it? If I make a Bitmap out of the URI, how do I display the Bitmap?
I'm just probably missing something simple...so any help would be a greatly appreciated!
Also additional question for thought: If I were to take multiple pictures, would you recommend me to use the SimpleCursorAdapter instead?
Thanks!