fluttercommunity / fluttercommunity/flutter_downloader

re-download fail below Android 10

Open
#585 0 comments 8 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
940
Forks
561
Avg merge
1h 18m
Merged PRs (30d)
1

Description

In Android 10(Q) or higher, `createFileInPublicDownloadsDir` method called. Then duplicate downloads are possible.
https://github.com/fluttercommunity/flutter_downloader/blob/0ac8d220a6da6daf435e652c77cd64ac9e36a26e/android/src/main/java/vn/hunghd/flutterdownloader/DownloadWorker.java#L506-L521

And Android 10(Q) or higher, auto-increment is misplaced when file names are duplicates, below picture.

In Android 10 below, `createFileInAppSpecificDir` method throw an error "It looks like you are trying to save file in public storage but not setting 'saveInPublicStorage' to 'true'" even thouth setting it to `true`.
https://github.com/fluttercommunity/flutter_downloader/blob/0ac8d220a6da6daf435e652c77cd64ac9e36a26e/android/src/main/java/vn/hunghd/flutterdownloader/DownloadWorker.java#L487-L501

I hope the following code is added.
```java
private File getUniqueFileName(String fileName, String savedDir) {
int num = 1;
String extension = getExtension(fileName);
String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."));
File file = new File(savedDir, fileName);
while (file.exists()) {
fileName = fileNameWithoutExtension + "(" + (num++) + ")" + extension;
file = new File(savedDir, fileName);
}
return file;
}

private String getExtension(String name) {
return name.substring(name.lastIndexOf("."));
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.