Android gets multiple recent photos from the album (get the photos stored by the camera)

Source: Internet
Author: User

Android gets multiple recent photos from the album (get the photos stored by the camera)


When you are working on a company project, you need to customize the grid view of the displayed photos to display the first 20 photos that you have taken with a recent camera.

I checked the API provided by the system and did not find the path constant pointing directly to storing photos after taking photos with a camera. If anyone knows, please let me know. Thank you!

The following is an example of my stupid method. The main code snippet is as follows:


// Obtain the path of the SDcard 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); // sort the while (mCursor. moveToNext () {// print the 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. You can only retrieve the image String path = mCursor in the photo album that stores the photo after taking the photo. getString (mCursor. getColumnIndex (MediaStore. images. media. DATA); if (path. startsWith (sdcardPath +/DCIM/100 MEDIA) | path. startsWith (sdcardPath +/DCIM/Camera/) | path. startsWith (sdcardPath + DCIM/100 Andro) {Log. I (image path =, path); img_path.add (file: // + path) ;}} mCursor. close ();


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: 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.