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:
Gets the path of the SDcard card String Sdcardpath = Environment.getexternalstoragedirectory (). toString (); Contentresolver mcontentresolver = MainActivity.this.getContentResolver (); Cursor mcursor = Mcontentresolver.query (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, New String[]{mediast Ore. 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.im Ages. media._id + "DESC"); Sort by Image ID descending while (mcursor.movetonext ()) {//print log to view the value of the photo id long id = mcursor.getlong (mcurso R.getcolumnindex (mediastore.images.media._id)); LOG.I ("mediastore.images.media_id=", ID + ""); Filter out unwanted images, just get pictures of photos stored in the photo album after the picture String path = mcursor.getstring (Mcursor.getcolumnindex (MEDIASTORE.IMAGES.MEDIA.D ATA)); 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)