Home Ask Login Register

Developers Planet

Your answer is one click away!

Tin_Ram February 2016

Display last captured photo in a imageView? (Camera)

So actually I have an application, where you can take a photo about yourself, and then it's saves the photo inside the phone, in a created folder called MyCameraApp.

I want to show the last captured photo from my MyCameraApp folder to an imageview in my activity.

I have no idea how to do this, every tutorial or example i founded is looks really complicated for me, after 3-4 hour of search I think it's better to ask this community, hope someone can help to me :)

Here's my code:

        public void onPictureTaken(byte[] data, Camera camera) {
            File pictureFile = getOutputMediaFile();
            if (pictureFile == null) {
            try {
                FileOutputStream fos = new FileOutputStream(pictureFile);
            } catch (FileNotFoundException e) {

            } catch (IOException e) {

    private static File getOutputMediaFile() {
        File mediaStorageDir = new File(
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d("MyCameraApp", "failed to create directory");
                return null;
        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                .format(new Date());
        File mediaFile;
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp + ".jpg");

        return mediaFile;

I know it's sound dumb, but I want something like this:

Get last created mediafile


Sam February 2016

The process might be the following:

  • Capture picture (you have it)
  • Save it to storage (you have it)
  • Load Bitmap from storage
  • Use setImageBitmap()

Loading from storage is achieved by using by BitmapFactory.decodeFile(*) for example on the same file object (pictureFile in your case)

Post Status

Asked in February 2016
Viewed 2,451 times
Voted 7
Answered 1 times


Leave an answer

Quote of the day: live life