I know the basics on how to take a picture and set it to ImageView.
photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
I want to do a little more than that.
I am saving it to a folder on to an SD card. That I have done successfully with this:
// intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, CAMERA_REQUEST);
Here is my next question:
Not sure how to do this: What I'd like to do next: The next time I come to this Activity
, I'd like to check if that image exists and assign it to that imageView
.
Last days i faced this issue in one of my applications.
I'll try here to explain a little bitte what i have done.
- Try to save the picture full path to a storage area or to your sharedpreferences.
- Next time if you call your activity then check if a picture already exists and if you can use it.
- Prepare in your xml layout an ImageView with visibility="gone" and if the point (2.) is true then you can change the visibility to visible and set the image in the view.
- If the point (2.) is false then switch to camera view (SurfaceView) in order to take a new picture
You would have to use some sort of persistent storage to reference the file to check if it exists. I would just store it as a string in a preference and read it, then check if it exists and so on. Easy enough to do from the onCreate()
.