How to Manage Your Android Phone Camera Programmatically


That time I think i make different with my Android Phone Camera. and also i want to share with you my that source code who help you in if you want to make different thing like me.

You also interact with your camera by many ways. One is simple you go to your gallery and use normal way.
 
Second way you go to Google Play Store and download other app for you. You use them.

But you don't have control on your camera.

Then you use that Code and enjoy and handle your camera.

First you create a project Camera testing in Eclipse

Go to file section and click on New Android Project

And fill the section.

And then you come on CameraActivity.java

Then you come on AndroidManifest.xml to gave the permission for camera activity.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example."
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <!-- YOU CAN USE THAT PERMISSION FOR CAMERA AND EXTERNAL HARDWARE FOR STOREGE -->
   <uses-feature android:name="android.hardware.camera" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/image1"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.CAMERAAPP.CameraActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|keyboard|keyboardHidden"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
    </application>

</manifest>/

I did not use any button and other image if you want to use any button then you come on activity.xml. If you want to use the activity.xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

   <Button

        android:id="@+id/btnCapture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Camera" />

</LinearLayout>/


Then finally we started the CameraActivity.java Coding

package com.example.CAMERAAPP.CameraActivity;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity {

   
    int TAKEPHOTO_CODE = 100;
    public static final int MEDIA_TYPE_IMAGE = 1;
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //here,we are making a folder named picFolder to store pics taken by the camera using this application
        final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MYPICTURES) + "/abhiFolder/"; 
        File newdir = new File(dir); 
        newdir.mkdirs();

     LinearLayout Camera = (LinearLayout) findViewById(R.id.btnCapture);
       Camera.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

           startActivityForResult(intent, TAKEPHOTO_CODE );

            }

        });

   
       @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == TAKEPHOTO_CODE  && resultCode == RESULT_OK) {

Log.d("TAKEPHOHO_CODE","RESULT_OK")

}      

    }

Thank you if anyone have good suggestion please tell me.



No comments:

Post a Comment