Android - SPLessons

Android Camera

Chapter 17

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Android Camera

Android Camera

The Android framework supports various cameras and its features to allow you capture images and videos in your applications. In this lesson, we will give you a quick view about how to integrate and control camera in your application.

Implementation of camera in your application can be done through the integration of an existing Android Camera application. You can start the existing Android Camera application via an intent and use the returned data of the application to access the result. Also, you can directly integrate the camera into your application via the Camera API (which uses android.hardware.camera2, added in API Level 21). If you use the Camera API, you need to add the following permissions.

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

Basic classes of Camera Intent and API:

The following example illustrates how to use an inbuilt camera application in the application using intents.

First create under src/<your packagename> in your application.

public class MainActivity extends Activity {

            //variable declaration
            private static final int CAMERA= 0;
            Context context;
            ImageView image;
    protected void onCreate(Bundle arg0) {

            //hide action bar
            //set activity to external view

        Button camera=(Button)findViewById(;

        //on click camera
        camera.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(i, CAMERA);

        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");


Create activity_main.xml under res/layout folder


    <Button />