Capture and Pick Images (From Gallery) to Display in ImageView | Android Application Development Tutorial

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 which can take picture using default android camera app. And Display that in ImageView Widget. 

The concept is as simple as it can get, We will create and App which contain two Buttons, one for camera and another one for gallery. When camera button is clicked, camera is opened and user can capture and image. 

This concept is useful for kind of android app where user can upload image in to the app. Like changing the profile image. So, generally user can select image either using gallery or user can simply start camera to capture 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 end of this article. 

  • 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 Camera and gallery we need permission from the user to user both camera and gallery. We need to specify , what are the resources that our application need 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 path of the image that is taken by the camera. so lets 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 image as well as select the image from 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 Part here. 

Full Source code is available at Github. Here

No comments

Powered by Blogger.