2

Is there a way, from within my own application, to open up the default camera app and use that to get a picture/video? I keep trying to look it up but I only ever find instructions on cloning the camera app myself (usually with very bad instructions). I know this can be done with the iPhone, I would be surprised if it wasn't possible with Android.

3 Answers3

3

To get the camera to take a picture and then get the image that it just took use the following

// Call to take the picture using the default camera
startActivityForResult(new Intent("android.media.action.IMAGE_CAPTURE"), PICK_FROM_CAMERA);

// After the camera intent finished returns the uri of the image taken
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == PICK_FROM_CAMERA)
    {
        Uri uri = data.getData();
                // set the imageview image via uri 
                _previewImage.setImageURI(uri);
    }
}
jfarrell
  • 4,480
  • 3
  • 21
  • 14
  • thank you very much for the snippet. It is exactly what I was looking for. No need to implement the camera functionality again while there is a perfect implementation... – dds May 02 '11 at 23:04
2

Here's some sample code where he starts the Camera intent and gets the image taken:

http://www.androidph.com/2008/11/camera-capture.html

(Warning, it's about a year old, so it will need a little updating).

marcc
  • 12,295
  • 7
  • 49
  • 59
2

Yep, you can. That's one of the ideas behind Android's intents.

Take a look here.

Dimitar Dimitrov
  • 16,032
  • 5
  • 53
  • 55