Created
July 25, 2020 23:57
-
-
Save jisungbin/853294b43186c0331cccacdc9cc18717 to your computer and use it in GitHub Desktop.
getAllImagePaths
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
fun getAllShownImagesPath(activity: Activity): MutableList<Uri> { | |
val uriExternal: Uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI | |
val cursor: Cursor? | |
val columnIndexID: Int | |
val listOfAllImages: MutableList<Uri> = mutableListOf() | |
val projection = arrayOf(MediaStore.Images.Media._ID) | |
var imageId: Long | |
cursor = activity.contentResolver.query(uriExternal, projection, null, null, null) | |
if (cursor != null) { | |
columnIndexID = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID) | |
while (cursor.moveToNext()) { | |
imageId = cursor.getLong(columnIndexID) | |
val uriImage = Uri.withAppendedPath(uriExternal, "" + imageId) | |
listOfAllImages.add(uriImage) | |
} | |
cursor.close() | |
} | |
return listOfAllImages | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment