Skip to content

Commit

Permalink
fix delete() not falling back to normal File#delete() (#871)
Browse files Browse the repository at this point in the history
When delete() was called, the plugin first tried to remove the file using
MediaStore, and then was (trying to) fall back to normal File#delete().
Unfortunately, the calls to MediaStore were throwing a SecurityException, so
the fall-back code was never executed.
  • Loading branch information
bartekpacia authored Jul 30, 2023
1 parent 15bfecd commit 387588f
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.MediaStore
import android.util.Log
import androidx.core.app.NotificationManagerCompat
import androidx.work.BackoffPolicy
import androidx.work.Constraints
Expand Down Expand Up @@ -390,7 +391,14 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin {
val saveFilePath = task.savedDir + File.separator + filename
val tempFile = File(saveFilePath)
if (tempFile.exists()) {
deleteFileInMediaStore(tempFile)
try {
deleteFileInMediaStore(tempFile)
} catch (e: SecurityException) {
Log.d(
"FlutterDownloader",
"Failed to delete file in media store, will fall back to normal delete()"
)
}
tempFile.delete()
}
}
Expand Down

0 comments on commit 387588f

Please sign in to comment.