Android gets multiple recently taken photos from albums (Get photos stored by camera photo)

Source: Internet
Author: User

Reprint please indicate source: http://blog.csdn.net/android_ls/article/details/39928519

When you are working on a company project, you encounter the need to customize the grid view that displays your photos, showing the top 20 photos taken by the user recently with the camera.

I looked at the system provides the API, did not find a direct point to take pictures after the camera to store the path constant, if you know, please tell me, thank you!

Here is the stupid way I used, the main code snippet is as follows:

  Get SDcard Card path   string sdcardpath = environment.getexternalstoragedirectory (). ToString ();   contentresolver mcontentresolver = mainactivity.this.getcontentresolver ( );   cursor mcursor = mcontentresolver.query (MediaStore.Images.Media.EXTERNAL_CONTENT_ uri,     new string[]{mediastore.images.media._id,  mediastore.images.media.data},     mediastore.images.media.mime_type +  "=?  OR  " + MediaStore.Images.Media.MIME_TYPE + " = ",      new string[] {  "Image/jpeg",  "Image/png"  }, mediastore.images.media._id +   " desc"); //  sorted by Image ID in descending order   while  (Mcursor.movetonext ())  {       //  Print Log to view the value of the photo ID       long id =  Mcursor.getlong (Mcursor.getcolumnindex (mediastOre. images.media._id));       LOG.I ("mediastore.images.media_id=",  id +   "");            //  filter out unwanted images, Only get pictures in albums that store photos after taking pictures       string path = mcursor.getstring ( Mcursor.getcolumnindex (MediaStore.Images.Media.DATA));      if  ( Path.startswith (sdcardpath +  "/dcim/100media")  | |  path.startswith (sdcardpath +  "/dcim/camera/")         | |  path.startswith (sdcardpath +  "Dcim/100andro"))  {    log.i ("image  path= ",  path);     img_path.add (" file://" + path);       }  }  mcursor.close ();


Android gets multiple recently taken photos from albums (Get photos stored by camera photo)

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.