Take photo with my device camera

Yesterday I learned how to look up image in a gallery and copy it into my app. Today I have to learn to take a photo instead of using an existing one.

1. Gist of it is explained in android doc

Use the Camera.takePicture() method to take a picture once the preview is started. You can createCamera.PictureCallback and Camera.ShutterCallback objects and pass them intoCamera.takePicture().

2. Code from http://developer.android.com/training/camera/photobasics.html starts camera and allows to take a picture. This is great. How do I get the image into my app?

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, actionCode);

3. onActionResult added code

Bundle extras = imageReturnedIntent.getExtras();
Bitmap yourSelectedImage = (Bitmap) extras.get(“data”);
this.mImageViewAllergen.setImageBitmap(yourSelectedImage);

This is working! Yey. Image is saved in a gallery. I don’t need it to be there but it’s ok.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s