Skip to content

Commit 68df215

Browse files
authored
Update EasyMedia.kt
修改managedQuery造成的bug
1 parent 797dbed commit 68df215

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

utils/src/main/java/com/haoge/easyandroid/easy/EasyMedia.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,18 @@ class EasyMedia {
473473

474474
private fun uriToFile(activity: Activity, data: Uri,type:Int):File {
475475
val cursor = activity.managedQuery(data, arrayOf(if(type == 1)MediaStore.Audio.Media.DATA else MediaStore.Video.Media.DATA), null,
476-
null, null)
476+
null, null)
477477
val path = if (cursor == null) {
478478
data.path
479479
} else {
480480
val index = cursor.getColumnIndexOrThrow(if(type == 1) MediaStore.Audio.Media.DATA else MediaStore.Video.Media.DATA)
481481
cursor.moveToFirst()
482482
cursor.getString(index)
483483
}
484-
cursor.close()
485-
return File(path)
484+
// 手动关掉报错如下
485+
// Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
486+
// cursor.close()
487+
return File(path)
486488
}
487489

488490
/***

0 commit comments

Comments
 (0)