How to open camera in android using intent and display the captured image

In this tutorial,we will learn how to open camera in  an android using intent and display the captured image into the ImageView in your android application step by step with easy explanation.

We can open the camera using  ACTION_IMAGE_CAPTURE of the MediaStore class.

Let’s start

1. activity_camera.xml:

 In the activity_camera.xml contains one imageview and one button.

 Imageview is used for the display the captured image and button is used for the open the  camera.

This is the java class where we will implement the logic for open the camera in an android and display the captured image into the imageview.

Button onClickListener=Here we will open the camera using intent.

onActivityResult( )=Here we will get the captured image.


<LinearLayout xmlns:androclass=””
android layout_heigth=”wrap_content”
android Orientation=”Vertical”
android layout_width=”wrap_content”>
android id=”@+id/captured_image
android layout_heigth=”400dp”
android layout_width=”wrap_content”/>
android id=”@+id/open_camera
android layout_heigth=”wrap_content”
android layout_width=”wrap_content”/>


import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;

Public class MainActivity extends Activity
ImageView displayImage;
Button openCamera;
private static int image_request_code=30;
protected void onCreate(Bundle savedInstanceState)


openCamera.setOnClickListener(new View.OnClickListener
Public void onClick (View v)

//This is onClickListener where we will open the camera using intent.
Intent intent=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);


//Here we will get the captured image and display into the imageview
protected void onActivityResult(int requestCode,int resultCode,Intent data)
Bitmap image=(Bitmap) data.getExtras( ).get(“data”);
displayImage.setImageBitmap(image); //Display image into the imageview



Example of Android camera intent

Hope,I explained very well about  android camera and if you still have any  query,comment me.

Thanks and Regards

Placement preparation


Hello Friends,I have written and developed this website because you can learn technology easily ,prepare for the placement and also for the any type of examination . By :Suman Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *