Android Code to Capture Image Using the Built-In Camera App

The simplest way to capture an image is to use Android’s built-In camera app capabilities via the intent filter. The intent filter of the built in camera app is named:

Accordingly to access this function you simply need to create an intent that would be caught by the above filter. In addition you need to procesws the image returned as a result of camera click.

Intent i = new Intent("");
startActivityForResult(i, CAMERA_RESULT);



Here’s a basic example that starts a new activity with intent

package com.knowpapa.camerademo; 

import android.content.Intent; 
import android.os.Bundle; 
import android.widget.ImageView; 

public class CameraDemo extends Activity { 

final static int CAMERA_OUTPUT = 0; 

ImageView imv; 

public void onCreate(Bundle savedInstanceState) { 
Intent i = new Intent("");
startActivityForResult(i, CAMERA_RESULT); 


protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 
super.onActivityResult(requestCode, resultCode, intent); 

if (resultCode == RESULT_OK) 
Get Bundle extras = intent.getExtras(); 
Bitmap bmp = (Bitmap) extras.get("data"); 
imv = (ImageView) findViewById(; 

Notice that the image returned by the camera application is passed as an extra named ‘data’ through to the intent of the calling activity. The ‘data’ contains a Bitma object,that we cast  to a generic Object.

Bundle extras = intent.getExtras();
Bitmap bmp = (Bitmap) extras.get("data");

A sample associated layout file in res/layout/camerapreview.xml is a s follows:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="" 
<ImageView android:id="@+id/ResultingImage" android:layout_width="wrap_content"

And finally the contents of AndroidManifest.xml for the sake of completeness:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="" 
android:versionName="1.0" package="com.knowpapa.camerademo"> 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 
<activity android:name=".CameraDemo" 
<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LAUNCHER" /> 
<uses-sdk android:minSdkVersion="4" /> 

An alternative method to capture images uses the actual camera hardware module to access camera hardware directly thus providing more control over what you can do with the camera. This is demonstrated in the next example.