Skip to content

Commit 387588f

Browse files
authored
fix delete() not falling back to normal File#delete() (#871)
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.
1 parent 15bfecd commit 387588f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.content.Context
66
import android.content.Intent
77
import android.net.Uri
88
import android.provider.MediaStore
9+
import android.util.Log
910
import androidx.core.app.NotificationManagerCompat
1011
import androidx.work.BackoffPolicy
1112
import androidx.work.Constraints
@@ -390,7 +391,14 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin {
390391
val saveFilePath = task.savedDir + File.separator + filename
391392
val tempFile = File(saveFilePath)
392393
if (tempFile.exists()) {
393-
deleteFileInMediaStore(tempFile)
394+
try {
395+
deleteFileInMediaStore(tempFile)
396+
} catch (e: SecurityException) {
397+
Log.d(
398+
"FlutterDownloader",
399+
"Failed to delete file in media store, will fall back to normal delete()"
400+
)
401+
}
394402
tempFile.delete()
395403
}
396404
}

0 commit comments

Comments
 (0)