Skip to content

Commit

Permalink
🐛 Fix no returned ids after successful deletion on Android API 29+ (#…
Browse files Browse the repository at this point in the history
…1204)

When the file is created by the application itself, the URI can be deleted successfully without causing a `RecoverableSecurityException`.
  • Loading branch information
chocoyang-horizon authored Oct 15, 2024
1 parent 3a036a4 commit 4396e54
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PhotoManagerDeleteManager(val context: Context, private var activity: Acti
private var androidQDeleteRequestCode = 40070
private val androidQUriMap = mutableMapOf<String, Uri?>()
private val androidQSuccessIds = mutableListOf<String>()
private val androidQRemovedIds = mutableListOf<String>()

@RequiresApi(Build.VERSION_CODES.Q)
inner class AndroidQDeleteTask(
Expand Down Expand Up @@ -149,13 +150,15 @@ class PhotoManagerDeleteManager(val context: Context, private var activity: Acti
androidQUriMap.clear()
androidQUriMap.putAll(uris)
androidQSuccessIds.clear()
androidQRemovedIds.clear()
waitPermissionQueue.clear()

for (entry in uris) {
val uri = entry.value ?: continue
val id = entry.key
try {
cr.delete(uri, null, null)
androidQRemovedIds.add(id)
} catch (e: Exception) {
// request delete permission
if (e is RecoverableSecurityException) {
Expand All @@ -181,8 +184,9 @@ class PhotoManagerDeleteManager(val context: Context, private var activity: Acti
}
}

androidQHandler?.reply(androidQSuccessIds.toList())
androidQHandler?.reply(androidQSuccessIds.toList() + androidQRemovedIds.toList())
androidQSuccessIds.clear()
androidQRemovedIds.clear()
androidQHandler = null
}

Expand Down

0 comments on commit 4396e54

Please sign in to comment.