Android Gallery Image Picker

Android Gallery Image Picker

Android supports seamless integration of applications and content providers. Lot many things are handy provided to developers, which helps in reducing the code and consumes less time to integrate different features to app.

For example, if we have an application that allow user to change his profile picture. In this requirement user will be welling to browse his mobile gallery and pick a picture of his own to set his profile picture. Integrating this feature in traditional operating system, need lot of effort write code to integrate file browser. But in android we can use Intent.ACTION_PICK action to get this feature integrated .


In this tutorial, we are going to learn how to pick an Image from Gallery and display in our app.

Video Demo

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. By default my activity is

2. First create a layout in xml file naming activity_main.xml that contains Button for selecting image , and ImageView to display image and two TextViews for displaying URI path and original path of image.

3. In above layout you had seen i had set background to FrameLayout creating a border to ImageView for this we have to create an xml file under drawable directory naming border.xml.

4. Now there are only three main steps by which we can achieve our goal :

Step 1: Starting Intent

  • ACTION_PICK – Action Pick will open the picker in Android device.
  • setType(“image/*”) – This will set the type of picker i.e. all image type. So action_pick will open gallery.

Step 2: Receiving the gallery response
The selected image will result in onActivityforResult where we get the image URI and we convert the URI into real path via below method :

Step 3: After receiving response we have to compress the image
We have to compress and scale the image because large images can cause Exceptions so better to avoid exception. The below method is going to do this task and return a bitmap:

5. Finally  come to your and add the following code that we had discusses in above point.

6. Now, you are all done, run your app and you will get the output as shown in video.

Thanks. :)

Download Source Code


About the author

I am an Android developer for whom Android is the one and only love. I work as a freelancer which gets me and Android closer. I always love to share my learnings and love to learn from others knowledge too.

Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)