Android App Development

Android Video Capture Example using Camera


If we want to use the inbuilt Camera of our device by your application then we have to initiate the Intent for it.
By using android.provider.MediaStore class we can easily capture the video.
The device Camera application requests video capture using android.provider.MediaStore.ACTION_VIDEO_CAPTURE.
To launch the camera there is a need to initiate the intent by using startActivity(..) or startActivityForResult(..) method.

startActivity() and startActivityForResult() with Camera Video Capturing:


If we want to launch the Camera application without worrying about the result of the captured video,
then we can call this method:

Intent captureVideoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);


Here, to access the captured video from a camera activity, the camera intent must be initiated using this call. It not only allows to start the camera application, but also one can also expect to get a result in form of a captured video.

Intent captureVideoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);

To access the captured video we will override the callback method onActivityResult(…).
Here we get the data and compare the request code, which is the second argument of the startActivityForResult() method, that the video has captured.

Example with Code:

Let’s see how we can create the Camera video capturing example by using startActivity() and startActivityForResult() method.


  1. Create new Application CameraVideoCapturingExample.


First, we have to add some permissions to create the Camera application.
Add this in your manifest file.

<uses-feature android:name="" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />


Inside this, we add the three buttons and a video view.

<Button android:text="Capture Video"
<Button android:text="Capture Video without Data"
<Button android:text="Play Video"
<VideoView android:id="@+id/VideoView"

1st button is for capturing the video by expecting a result, which means it uses startActivityForResult().
2nd button is for only capturing the video without accessing the video, which means it uses startActivity().
3rd is to play the captured video. There is a condition that, if we capture the video by using startActivityForResult() then the play video button is enabled otherwise not.
VideoView is used to play the video that has been captured.

Here we will be using the VideoView object with Uri to play the captured video.

VideoView videoView;
public static int VIDEO_CAPTURED = 1;

It is a constant which is used as a request code in onActivityResult() method.

Add some code in onCreate(){…}

Take the reference of all buttons and video views and set the listeners on buttons.

captureVideoButton = (Button) this.findViewById(;
playVideoButton = (Button) this.findViewById(;
captureWithoutDataVideoButton = (Button) this.findViewById(;
videoView = (VideoView) this.findViewById(;

Initially, playVideoButton is not enabled. We will set enable when we capture the video.


Inside onClick() we can do this like:

if (v == captureVideoButton) {
Intent captureVideoIntent =new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
}if (v == captureWithoutDataVideoButton) {
Intent captureVideoIntent =new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
}else if (v == playVideoButton) {

And our captured video will be accessed through onActivityResult() method

Add some code in onActivityResult() method:

if (resultCode == RESULT_OK && requestCode == VIDEO_CAPTURED) {
videoFileUri = data.getData();


Before Capture Video

After Capture Video

While Play Video


This is the basic idea of how to create a similar camera application. We can customize it as per the need of the application and make it even better. It only shows how to launch the camera activity and get the data in return to capture the video. It finds usage in popular applications like Instagram. The camera functionality plays an important role in many applications and it is very popular in Android development.
Keep visiting our site for more updates on Android and other technologies.

One Comment

  1. I’ve come across that right now, more and more people will be attracted to cams and the area of photography. However, to be a photographer, you will need to first spend so much time deciding the model of photographic camera to buy as well as moving store to store just so you could possibly buy the lowest priced camera of the trademark you have decided to pick. But it would not end just there. You also have to think about whether you should purchase a digital digicam extended warranty. Thanks a bunch for the good ideas I acquired from your blog site.

Leave a Reply

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

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

Related Articles