Skip to content

Instantly share code, notes, and snippets.

@jianzhongli
Created January 1, 2016 14:28
Show Gist options
  • Save jianzhongli/791e5bdf153f30535fb9 to your computer and use it in GitHub Desktop.
Save jianzhongli/791e5bdf153f30535fb9 to your computer and use it in GitHub Desktop.
final private static String FILE_SLASH = "file:///";
public static ArrayList<Photo> getAllPhotos(Context context) {
ArrayList<Photo> listOfPhotos = new ArrayList<>();
String[] projection = {
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.DATE_TAKEN};
Cursor cursor = MediaStore.Images.Media.query(
context.getContentResolver(),
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
null, null, MediaStore.Images.ImageColumns.DATE_TAKEN
);
while (cursor.moveToNext()) {
String path = FILE_SLASH + cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
Long date = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATE_TAKEN));
Photo photo = new Photo(path, date);
listOfPhotos.add(photo);
}
cursor.close();
return listOfPhotos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment