open class Photo(val url: String)
fun Activity.getGalleryImages(): ArrayList<Photo> {
val galleryImageUrls: ArrayList<GalleryPickerFragment.Photo> = ArrayList()
val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID)
val orderBy = MediaStore.Images.Media.DATE_TAKEN
val imageCursor = this.contentResolver.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
columns,
null,
null,
"$orderBy DESC"
)
for (position in 0 until imageCursor.count) {
imageCursor.moveToPosition(position)
galleryImageUrls.add(
Photo(imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA)))
)
}
imageCursor.close()
return galleryImageUrls
}
Last active
February 13, 2019 08:39
-
-
Save delacrixmorgan/775dc99a51ccaff87bea5fc67958bb29 to your computer and use it in GitHub Desktop.
Fetch Gallery Images and Returning URLs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment