From ecad7ccea220f75880ae64e545ee37490d41757a Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Mon, 20 Feb 2017 20:20:06 +0100 Subject: [PATCH] Try not to lose filename extensions. Android's Storage Access Framework abstraction wants us to use mimetypes instead of file extensions, but for some file types it can't guess a useful mimetype. In those cases, provide the extension as part of the base name. BUG: 376638 --- .../kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index 46969342..0e83fd7c 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -119,11 +119,15 @@ public class SharePlugin extends Plugin { final String defaultPath = ShareSettingsActivity.getDefaultDestinationDirectory().getAbsolutePath(); final String filename = customDestination? originalFilename : FilesHelper.findNonExistingNameForNewFile(defaultPath, originalFilename); - final String nameWithoutExtension = FilesHelper.getFileNameWithoutExt(filename); + String displayName = FilesHelper.getFileNameWithoutExt(filename); final String mimeType = FilesHelper.getMimeTypeFromFile(filename); + if ("*/*".equals(mimeType)) { + displayName = filename; + } + final DocumentFile destinationFolderDocument = ShareSettingsActivity.getDestinationDirectory(context); - final DocumentFile destinationDocument = destinationFolderDocument.createFile(mimeType, nameWithoutExtension); + final DocumentFile destinationDocument = destinationFolderDocument.createFile(mimeType, displayName); final OutputStream destinationOutput = context.getContentResolver().openOutputStream(destinationDocument.getUri()); final Uri destinationUri = destinationDocument.getUri();