Created
August 13, 2019 07:25
-
-
Save yudikarma/b617ed0511817ea39b6c3f63abda4f49 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 getImagelist(): ArrayList<GaleryFragmentModel> { | |
var dataLocal = ArrayList<GaleryFragmentModel>() | |
var absolutePathOfFile: String? = null | |
val projection = arrayOf( | |
MediaStore.Files.FileColumns.DATA, | |
MediaStore.Files.FileColumns.DATE_ADDED, | |
MediaStore.Files.FileColumns.MEDIA_TYPE) | |
val selection:String = (MediaStore.Files.FileColumns.MEDIA_TYPE + "=" | |
+ MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE | |
+ " OR " | |
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "=" | |
+ MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO) | |
val queryUri = MediaStore.Files.getContentUri("external") | |
val cursorLoader = CursorLoader(context,queryUri,projection,selection,null,MediaStore.Files.FileColumns.DATE_ADDED + " DESC") | |
val cursor = cursorLoader.loadInBackground() | |
cursor?.let { | |
while (it.moveToNext()){ | |
val dataColumnIndex = it.getColumnIndex(MediaStore.Files.FileColumns.DATA) | |
val typeMedia = it.getColumnIndex(MediaStore.Files.FileColumns.MEDIA_TYPE) | |
absolutePathOfFile = it.getString(dataColumnIndex) | |
val mediaType = it.getInt(typeMedia)/*1 == image , 3 == video*/ | |
absolutePathOfFile?.let { pathfile -> | |
galeryFragmentModel = GaleryFragmentModel(pathfile,mediaType) | |
galeryFragmentModel?.let { | |
dataLocal.add(it) | |
} | |
} | |
} | |
} | |
cursor?.close() | |
return dataLocal | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment