Android Camera

Android Camera

Android Camera  and Android Video Camera are includes in Android Platform, letting you take videos and pictures in your applications. This tutorial discusses an instant, simple approach to video and image capture and outlines an advanced approach for creating custom camera experience for users

These are the next two ways, where you may use camera in the application

  • By Using existing android camera app inside our application
  • By Using Camera API provided by android inside our app ( We Explained in  Camera API)

In This Tutorial We Will Explain Following

By Using Existing Android Camera App Inside Our Application

You shall use MediaStore.ACTION_IMAGE_Take to launch a preexisting camera application installed on your phone. Its syntax and code is listed below

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);


From the above apart, there are other available Intents provided by MediaStore. They can be listed the following

Intent Types and Descriptions


It results the PIC captured from the android camera , when these devices is secured


It calls the prevailing video request in android to fully capture video


It can be used to create the orientation of the display to vertical or landscape


It can be used to control an individual user interface of the ViewImage


This intent can be used to release the camera in the training video mode


It is employed to specify the size limit of video or image capture size

Now you use the function startActivityForResult() to unveiling this activity and await its end result. Its CODE  is listed below



This technique has been identified in the activity class. Were contacting it from main activity. A couple of methods defined in the experience class that does the same job , but used if you are not calling from the experience but from someplace else. They are the following

Activity Function &  Descriptions


An activity is started out because of it , but may take extra package of options with it


It launch the experience whenever your activity is child of another activity


It work identical to above , but normally it takes extra ideals in the condition of bundle with it


It launches activity from the fragment you are inside presently


It not only launches the experience from the fragment , but may take extra beliefs with it

Whichever function you used to establish the activity , each of them give back the effect. The result can be acquired by overriding the function onActivityResult.

Android Camera Example

Here is a good android camera example that presents how to release the prevailing android camera application to fully capture a graphic and screen the bring about the proper execution of bitmap

To test out this android example , you will need to perform this on a genuine device which camera is recognized.

Steps     Description

  1. You use Android studio IDE to set-up an Android program and name it as Camera under a com.example.sappal.myapplication
  2. Modify src/ to include objective code to establish the experience and consequence solution to recieve the productivity.
  3. Modify design XML res/design/activity_main.xml add any GUI aspect if required. Here we add only imageView and a textView.
  4. Run the application form and choose a jogging android os device and set up the application onto it and validate the results.

Following is this content of the changed main activity data file src/

package com.example.sappal.myapplication;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;

import android.os.BatteryManager;
import android.os.Bundle;

import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Set;

public class MainActivity extends ActionBarActivity {
   Button b1,b2;
   ImageView iv;
   protected void onCreate(Bundle savedInstanceState) {
      b1.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, 0);
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      // TODO Auto-generated method stub
      super.onActivityResult(requestCode, resultCode, data);
      Bitmap bp = (Bitmap) data.getExtras().get("data");
   protected void onDestroy() {
   public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(, menu);
      return true;
   public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      //noinspection SimplifiableIfStatement
      if (id == {
         return true;
      return super.onOptionsItemSelected(item);


Here is the content of res/layout/activity_main.xml file

Do You Have Any Question About This Tutorial? Ask Question Now On Andro Development & Get Answer Instantly. No Signup/Login Needed

<RelativeLayout xmlns:android=""
   xmlns:tools="" android:layout_width="match_parent"
   android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
   <TextView android:text="Camera Example" android:layout_width="wrap_content"
      android:layout_centerHorizontal="true" />
      android:text="Andro Development"
      android:textSize="35dp" />
      android:layout_centerHorizontal="true" />
      android:layout_marginTop="86dp" />


Following will be the content of res/values/strings.xml to define one new constants

   <string name="app_name">My Application</string>
   <string name="hello_world">Hello world!</string>
   <string name="action_settings">Settings</string>


Following is the default content of AndroidManifest.xml 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
   android:versionName="1.0" >

      android:theme="@style/AppTheme" >
         android:label="@string/app_name" >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />

Let’s make an effort to run the application. I suppose you have linked your actual Google android Mobile device with your personal computer. To perform the app from Android studio room, available one of your project’s activity documents and click Run Eclipse Run Icon from the tool. Before starting the application, Android studio room will display pursuing window to choose a choice where you want to perform your Android software.

android camera

Choose your mobile device as a choice and check your mobile device that may screen pursuing display then

android camera

Now just touch on the button on and the camera will be opened up. Capture a picture just. After capturing it , two buttons can look requesting to discard it or keep it

android camera

Just press the tic button and you’ll be cut back to the application with the captured image instead of android icon

android camera

Do You Have Any Question About This Tutorial? Ask Question Now On Andro Development & Get Answer Instantly. No Signup/Login Needed