Android Camera

In android app development the Camera is useful to capture the photos and videos in our applications and by using the camera API we can control the functionalities of the camera based on our requirements.

The android framework provides two ways such as android.hardware.camera2 API and camera intent to capture the images and videos in our application.


The intent action types either MediaStore.ACTION_IMAGE_CAPTURE or MediaStore.ACTION_VIDEO_CAPTURE and you can capture the videos / photos without directly using the Camera object.

The right way is to use the Intent to invoke an existing Android app camera application to take photos and videos in our app without writing a lot of extra code.

By using startActivityForResult() function with intent action parameter MediaStore.ACTION_IMAGE_CAPTURE, you can take the pictures from our android applications.

Following is the code to capture the pictures using the intent object with action parameter MediaStore.ACTION_IMAGE_CAPTURE in android applications.

Intent cInt = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

Android Camera App Example

Following is the example of using an existing camera app in our android app to capture the photos on click button.
Create a new android app using android studio and give names as CameraExample and In case if we are not aware of creating an app in android studio check this article Android Hello World App.
Once you create an application, open activity_main.xml file from \res\layout folder path and write the code like as shown below.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
       android:text="TAKE PICTURE"
       android:layout_alignParentBottom="true" />

Now open your main activity file in from path and write the code like as shown below

package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity{
   private Button btnCapture;
   private ImageView imgCapture;
   private static final int Image_Capture_Code = 1;

   protected void onCreate(Bundle savedInstanceState) {

       btnCapture =(Button)findViewById(;
       imgCapture = (ImageView) findViewById(;
       btnCapture.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               Intent cInt = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       super.onActivityResult(requestCode, resultCode, data);
       if (requestCode == Image_Capture_Code) {
           if (resultCode == RESULT_OK) {
               Bitmap bp = (Bitmap) data.getExtras().get("data");
           } else if (resultCode == RESULT_CANCELED) {
               Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();


If we observe the above code snippet, you used startActivityForResult() method with MediaStore.ACTION_IMAGE_CAPTURE intent action parameter to capture the pictures.
When you run the above app in the android studio you will get the output as shown below.

When you click on the Take a Photo button and the camera will start and you can take the picture of whatever you want and the captured image can be shown in a defined imageview.

Subscribe Now