1. Download our Official Android App: Forums for Android!

Apps Hooking into the native camera

Discussion in 'Android Development' started by sehudson, Sep 29, 2011.

  1. sehudson

    sehudson Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    Feb 2, 2011

    Feb 2, 2011
    17
    0
    15
    I need to take pictures with my application, but the only thing I am finding are examples of how to create a camera activity. Is there a way I can call up the phones native camera instead and get the byte[] data back instead of creating a camera activity myself?

    I am asking because I would like to take advantage of the normal features like zoom, flash, themes, etc that the user would get if they push the camera button on their phone.
     

    Advertisement

  2. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    You can call the phones native camera application, and you can get back the picture taken. But the picture returned are scaled down because Android don't want developers to get the picture back this way. The best way is to call the native camera app and instead of getting back the picture, you get back a Uri.

    Code (Text):
    1.  
    2. public void captureImage()
    3. {
    4.     ContentValues values = new ContentValues();
    5.     values.put(Media.TITLE, "Captured Image");
    6.     values.put(Media.DESCRIPTION, "Image captured with native camera app");
    7.    
    8.     image = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values); //this is a Uri object which should be defined as a 'private Uri image;' outside methods in the class.
    9.    
    10.     Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    11.     i.putExtra(MediaStore.EXTRA_OUTPUT, image);
    12.    
    13.     startActivityForResult(i, 0);
    14. }
     

Share This Page

Loading...