postheadericon Camera Example in Android



Definition: Create an application to take picture using native application


File Name :


package bsr.exa;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class E22Activity extends Activity {
    /** Called when the activity is first created. */
    ImageView iv;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        iv=(ImageView)findViewById(R.id.imageView1);
        Button b =(Button)findViewById(R.id.button1);
        b.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, 0);
}
});
    }
protected void OnActivityResult(int requestCode,int resultcode,Intent data)
{
Bitmap bm=(Bitmap)data.getExtras().get("data");
iv.setImageBitmap(bm);
}
}

File Name : AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="bsr.exa"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.CAMERA"></uses-permission>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".E22Activity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>





0 comments:

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.