Android Create Simple Camera App with source code example tutorial

How to start open front camera in android programmatically using intent on button click.

Camera is one of the major part of an android mobile phone device and there are lot’s of or we can say thousands of camera android applications available on Google Play Store to handle camera events. So in this tutorial we are going to make our own camera android mobile phone application which will help us to enable + handle our device camera on button click. So here is the complete step by step tutorial for Android Create Simple Camera App with source code example tutorial.

android-project-download-code-button

Android Create Simple Camera App with source code example tutorial.

Code for MainActivity.java file.

 package com.cameraapp_android_examples.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

 Button button;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 button = (Button)findViewById(R.id.button1);
 
 button.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
 
 startActivityForResult(intent, 0);
 
 }
 });
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.cameraapp_android_examples.com.MainActivity" >

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Click Here to start camera in android programmatically" />

</RelativeLayout>

Screenshot :

Android Create Simple Camera App with source code example tutorial

Click here to download Android Create Simple Camera App with source code example tutorial project with source code.

Leave a Reply

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