SimpleStorage
SimpleStorage copied to clipboard
File extension lost
Library version: 1.5.6 OS version: Android 14 Device model: Pixel 7a
Describe the bug Hi, I have an issue with your library. The file extension is lost when creating a file in the Downloads folder.
Do you know a workaround for it?
To Reproduce
All this doesn't work...
FileDescription description = new FileDescription("test.gpx", "", "");
DocumentFileCompat.createDownloadWithMediaStoreFallback(getApplicationContext(), description);
FileDescription description = new FileDescription("test.gpx", "", null);
DocumentFileCompat.createDownloadWithMediaStoreFallback(getApplicationContext(), description);
FileDescription description = new FileDescription("test.gpx", "", "application/gpx+xml");
DocumentFileCompat.createDownloadWithMediaStoreFallback(getApplicationContext(), description);
however, this does work:
FileDescription description = new FileDescription("test.png", "", "image/png");
DocumentFileCompat.createDownloadWithMediaStoreFallback(getApplicationContext(), description);
Reference https://github.com/fm-sys/snapdrop-android/issues/309
@anggrayudi any idea? Thank you!
Does this only happen on Android 14?
At least Android 13 is affected as well, didn't have checked other versions until now though.
It happened on Android 10 and 12 as well.
Fixed in v2.1.0
But please bear in mind that Android OS can't recognize all mime types. So, if a file duplication happens, it will create filename.gpx (1) instead of filename (1).gpx, because the OS doesn't recognize mime type application/gpx+xml. This is the limitation of Android OS, I can't fix it. To check if the mime type is recognized can be done via:
val isRecognized = MimeTypeMap.getSingleton().getExtensionFromMimeType(file.mimeType) != null