SimpleStorage icon indicating copy to clipboard operation
SimpleStorage copied to clipboard

File extension lost

Open fm-sys opened this issue 1 year ago • 4 comments

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);

grafik


Reference https://github.com/fm-sys/snapdrop-android/issues/309

fm-sys avatar Jul 27 '24 17:07 fm-sys

@anggrayudi any idea? Thank you!

fm-sys avatar Jul 30 '24 13:07 fm-sys

Does this only happen on Android 14?

anggrayudi avatar Jul 30 '24 20:07 anggrayudi

At least Android 13 is affected as well, didn't have checked other versions until now though.

fm-sys avatar Jul 30 '24 20:07 fm-sys

It happened on Android 10 and 12 as well.

christaikobo avatar Apr 07 '25 20:04 christaikobo

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

anggrayudi avatar Jun 11 '25 15:06 anggrayudi