Created
January 1, 2016 14:28
-
-
Save jianzhongli/791e5bdf153f30535fb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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