Capture & Display Image in Android ImageView

Learning to play with camera API of Android OS is fun, In this post, we will talk about android camera API and by the end of this article, you will be able to make an android application that can take a picture using default android camera app. And Display that in ImageView Widget. So we will be able to basically Capture & Display Image in Android ImageView.

The concept is as simple as it can get, We will create an App which contains two Buttons, one for the camera and another one for the gallery. When the camera button is clicked, the camera is opened and the user can capture an image. 
This concept is useful for the kind of android app where users can upload an image into the app. Like changing the profile image. So, generally, users can select images either using a gallery or user can simply start the camera to capture a brand new image. 
I hope you got some idea about whats this app is going to be in this tutorial. If not carry on and you will understand it by the end of this article. 
[the_ad id=”1212″]
  • Open Android Studio  and Create New App With Empty Activity 
  • Select The Target API as 23 or Above ( We Need to ask Run time Permission for Camera and Storage from the user ). 
The Initial Layout Of our android app is going to look like as shown below and Source code is given below as well.

The Source Code for XML layout Given above is : 

Since we need to use the Camera and gallery we need permission from the user to the user both camera and gallery. We need to specify, what are the resources that our application needs to function in the manifest file. 

we can specify them using <uses-permission> tag as shown below : 

We need to Provide the file provider to be able to retrieve the path of the image that is taken by the camera. so let’s add the  <provider> in Manifest File  The final Manifest.xml file looks like below.

Now We need to write all the codes that implement logic to take an image as well as select the image from the gallery. 

  • galleryAddpic() method is used to send the broadcast to MediaStore. So that our captured image will appear in Gallery. 
This Tutorial is Part of my Complete Youtube Tutorial Series. You can watch All the Parts here. 

Full Source code for Capture & Display Image in Android ImageView is available at Github. Here

We will be happy to hear your thoughts

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.