Source Code : Capture Image from Camera and Display in Activity

Capture Image from Camera and Display in Activity

MyCameraActivity.java
public class MyCameraActivity extends Activity {
  private static final int CAMERA_REQUEST = 1888;
  private ImageView imageView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  imageView = (ImageView)findViewById(R.id.imageView1);
  Button photoButton = (Button)findViewById(R.id.button1);
  photoButton.setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {
  Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  startActivityForResult(cameraIntent, CAMERA_REQUEST);
  }
  });
  }

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  if (requestCode == CAMERA_REQUEST) {  
  Bitmap photo = (Bitmap) data.getExtras().get("data");
  imageView.setImageBitmap(photo);
  }  

  }
}




main.xml

  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
    android:id="@+id/button1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="photo" >
 
    android:id="@+id/imageView1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:src="@drawable/ic_launcher" >
 



AndroidManifest.xml
 add in manifest