Oct 30, 2012

Displaying the taken picture – Instant Mustache #7

This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection. Click here to get a chronological list of all published articles about Instant Mustache.

Writing the PhotoActivity

In the last article we wrote the code to take a camera picture and save it on the external storage. After saving the file the activity will be finished and a Toast will show up. This is not really user-friendly so now we'll write our next activity which will display the taken picture and later offer the option to share this picture.

We'll start by creating an empty activity called PhotoActivity and add it to the manifest of our application. For now the layout will only contain an ImageView to display the picture:


Instead of showing a toast in our CameraActivity we create an Intent to start the PhotoActivity and use setData(Uri) on the Intent object to pass a Uri pointing to the picture file:

onPictureTaken() - CameraActivity.java

In onCreate(Bundle) of the PhotoActivity we'll retrieve the Uri from the Intent and pass it to the ImageView. The ImageView will take care of loading the picture from the external storage and displaying it.

onCreate() - PhotoActivity.java

And that's already all the code we need for the first version of the PhotoActivity.

CameraActivity (left) and PhotoActivity (right)


  1. How about utilising one of the popular pinch/zoom open source libraries on the photo activity? A photo isn't really a photo without pinch 'n zoom.

    I recall a couple of weeks ago the Android office hours (uk version) were talking to a guy in the hangout called Chris... (second name escapes me) and were singing praises about the pinch zoom library he'd published.

  2. Thanks martin! As said on Google plus: Yeah, Pinch-to-Zoom could be a good enhancement for a future version. Let's see what camera/gallery features are missed the most after the first release.

  3. Thanks for the Blog!! It is very resourceful!! I have always struggling on some camera API problem, and this blog provides all the solution!! keep it up!!