diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml
new file mode 100644
index 0000000..b6b1f44
--- /dev/null
+++ b/.idea/libraries/Dart_SDK.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml
new file mode 100644
index 0000000..b0f6971
--- /dev/null
+++ b/.idea/libraries/Flutter_Plugins.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..45ce507
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/photo_gallery.iml b/.idea/photo_gallery.iml
new file mode 100644
index 0000000..e13ef20
--- /dev/null
+++ b/.idea/photo_gallery.iml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..e764c08
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1606155210205
+
+
+ 1606155210205
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt b/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt
index eaeb0bc..e5d3dc0 100644
--- a/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt
+++ b/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt
@@ -277,13 +277,58 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
val limit = take ?: (total - offset)
this.context?.run {
- val imageCursor = this.contentResolver.query(
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
- imageMetadataProjection,
- if (albumId == allAlbumId) null else "${MediaStore.Images.Media.BUCKET_ID} = $albumId",
- null,
- "$imageOrderBy LIMIT $limit OFFSET $offset"
- )
+
+ var imageCursor: Cursor? = null
+
+ /**
+ * Change the way to fetch Media Store
+ */
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ // Get All data in Cursor by sorting in DESC order
+ imageCursor = this.contentResolver.query(
+ MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
+ imageMetadataProjection,
+ android.os.Bundle().apply {
+ // Limit & Offset
+ putInt(android.content.ContentResolver.QUERY_ARG_LIMIT, limit)
+ putInt(android.content.ContentResolver.QUERY_ARG_OFFSET, offset)
+ // Sort function
+ putStringArray(
+ android.content.ContentResolver.QUERY_ARG_SORT_COLUMNS,
+ arrayOf(
+ MediaStore.Images.Media.DATE_TAKEN,
+ MediaStore.Images.Media.DATE_MODIFIED
+ )
+ )
+ putIntArray(
+ android.content.ContentResolver.QUERY_ARG_SORT_DIRECTION,
+ intArrayOf(
+ android.content.ContentResolver.QUERY_SORT_DIRECTION_DESCENDING,
+ android.content.ContentResolver.QUERY_SORT_DIRECTION_DESCENDING
+ )
+ )
+ // Selection
+ if (albumId != allAlbumId) {
+ putString(android.content.ContentResolver.QUERY_ARG_SQL_SELECTION, "${MediaStore.Images.Media.BUCKET_ID} = ?")
+ putStringArray(
+ android.content.ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS,
+ arrayOf(
+ albumId.toString()
+ )
+ )
+ }
+ },
+ null
+ )
+ } else {
+ imageCursor = this.contentResolver.query(
+ MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
+ imageMetadataProjection,
+ if (albumId == allAlbumId) null else "${MediaStore.Images.Media.BUCKET_ID} = $albumId",
+ null,
+ "$imageOrderBy LIMIT $limit OFFSET $offset"
+ )
+ }
imageCursor?.use { cursor ->
while (cursor.moveToNext()) {