1 String DCIMPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath(); 2 3 ContentResolver mContentResolver = getActivity().getApplicationContext().getContentResolver(); 4 Cursor mCursor = mContentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 5 new String[]{MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA}, MediaStore.Images.Media.MIME_TYPE + "=? AND " + MediaStore.Images.Media.DATA + " like ? ", 6 new String[]{"image/jpeg", "%/DCIM/" + CameraFragment.ALBUM_NAME + "%"}, 7 MediaStore.Images.Media.DATE_MODIFIED + " DESC"); // 降序排列 8 9 if (mCursor != null) { 10 while (mCursor.moveToNext()) { 11 // 打印LOG查看照片ID的值 12 long id = mCursor.getLong(mCursor.getColumnIndex(MediaStore.Images.Media._ID)); 13 LogUtil.i("MediaStore.Images.Media_ID=" + id + ""); 14 15 // 过滤掉不需要的图片,只获取拍照后存储照片的相册里的图片 16 String path = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DATA)); 17 if (path.startsWith(DCIMPath + File.separator + ALBUM_NAME)) { 18 lastPhotoPath = path; 19 LogUtil.i("last photo path=" + lastPhotoPath); 20 break; 21 } 22 } 23 mCursor.close(); 24 }
时间: 2024-11-04 23:41:39