Android call system camera to save and call the System album method

Source: Internet
Author: User

System already has something, if we do not have new requirements, direct call is the most direct. Here's how to call a system camera to take pictures and save pictures and how to call a system photo album.

First look at the core method of calling the system camera:

Intent camera = new Intent (mediastore.action_image_capture);

Startactivityforresult (camera, 100);

The data returned by the camera is obtained by the following callback method and processed

@Override
 protected void onactivityresult (int requestcode, int resultcode, Intent data) {
  Super.onactivityresult (Requestcode, ResultCode, data);
      
  if (Requestcode = = CAMERA && ResultCode = ACTIVITY.RESULT_OK && null!= data) {
      Bundle Bundle = data.ge Textras ();
      Gets the data returned by the camera and converts it to a picture format
      Bitmap Bitmap = (Bitmap) bundle.get ("Data");
    }

Here's how to call a system photo album and get a Photo:

Intent picture = new Intent (Intent.action_pick,android.provider.mediastore.images.media.external_content_uri);

Startactivityforresult (picture, 101);

Or

Intent = new Intent (), Intent.settype ("image/*"), Intent.setaction (intent.action_get_content);((activity). Startactivityforresult (Intent, 101);

The following callback methods are appropriate:

@Override
protected void onactivityresult (int requestcode, int resultcode, Intent data) {
   Super.onactivityresult (Requestcode, ResultCode, data);
      
   if (Requestcode = && ResultCode = = ACTIVITY.RESULT_OK && null!= data) {
      
   Uri selectedimage = data  . GetData ();
   String[] Filepathcolumns={mediastore.images.media.data};
   Cursor C = this.getcontentresolver (). Query (SelectedImage, Filepathcolumns, null,null, 

null);
   C.movetofirst ();
   int columnindex = C.getcolumnindex (Filepathcolumns[0]);
   String picturepath= c.getstring (columnindex);
    C.close ();
}
}

Or

@Override
protected void onactivityresult (int requestcode, int resultcode, Intent data) {
    if (ResultCode = = Activ ity. RESULT_OK) {
        switch (requestcode) {case
            :
                uri uri = Data.getdata ();
                Cursor Cursor = This.getcontentresolver (). Query (URI, NULL,
                        null, NULL, NULL);
                Cursor.movetofirst ();
String Imgno = cursor.getstring (0); Picture number 
String imgpath = cursor.getstring (1);//Picture file path 
string imgsize = cursor.getstring (2) ; Picture size 
String imgname = cursor.getstring (3);//Picture filename
                cursor.close ();
                Bitmap Bitmap = Bitmapfactory.decodefile (Imgpath);
                break;
    
            Default: Return;}}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.