update contentResolver.query calling and fix bugs

This commit is contained in:
Wenqi Li 2023-05-09 21:07:53 +08:00
parent 73f91d5c00
commit f8842c89a8

View File

@ -426,8 +426,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
val imageCursor = this.contentResolver.query( val imageCursor = this.contentResolver.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
imageMetadataProjection, imageMetadataProjection,
"${MediaStore.Images.Media._ID} = $mediumId", "${MediaStore.Images.Media._ID} = ?",
null, arrayOf(mediumId),
null null
) )
@ -448,9 +448,10 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
val videoCursor = this.contentResolver.query( val videoCursor = this.contentResolver.query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
videoMetadataProjection, videoMetadataProjection,
"${MediaStore.Images.Media._ID} = $mediumId", "${MediaStore.Video.Media._ID} = ?",
null, arrayOf(mediumId),
null) null
)
videoCursor?.use { cursor -> videoCursor?.use { cursor ->
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
@ -528,10 +529,11 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
null null
} }
} else { } else {
val kind = if (highQuality == true) MediaStore.Images.Thumbnails.MINI_KIND else MediaStore.Images.Thumbnails.MICRO_KIND val kind =
if (highQuality == true) MediaStore.Video.Thumbnails.MINI_KIND else MediaStore.Video.Thumbnails.MICRO_KIND
MediaStore.Video.Thumbnails.getThumbnail( MediaStore.Video.Thumbnails.getThumbnail(
this.contentResolver, mediumId.toLong(), this.contentResolver, mediumId.toLong(),
kind,null kind, null
) )
} }
} }
@ -672,7 +674,10 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
this.context?.run { this.context?.run {
mimeType?.let { mimeType?.let {
val type = this.contentResolver.getType( val type = this.contentResolver.getType(
ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, mediumId.toLong()) ContentUris.withAppendedId(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
mediumId.toLong()
)
) )
if (it != type) { if (it != type) {
return cacheImage(mediumId, it) return cacheImage(mediumId, it)
@ -682,8 +687,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
val imageCursor = this.contentResolver.query( val imageCursor = this.contentResolver.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
arrayOf(MediaStore.Images.Media.DATA), arrayOf(MediaStore.Images.Media.DATA),
"${MediaStore.Images.Media._ID} = $mediumId", "${MediaStore.Images.Media._ID} = ?",
null, arrayOf(mediumId),
null null
) )
@ -704,10 +709,11 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
this.context?.run { this.context?.run {
val videoCursor = this.contentResolver.query( val videoCursor = this.contentResolver.query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
arrayOf(MediaStore.Images.Media.DATA), arrayOf(MediaStore.Video.Media.DATA),
"${MediaStore.Images.Media._ID} = $mediumId", "${MediaStore.Video.Media._ID} = ?",
null, arrayOf(mediumId),
null) null
)
videoCursor?.use { cursor -> videoCursor?.use { cursor ->
if (cursor.moveToNext()) { if (cursor.moveToNext()) {