diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/FileBackend.java | 11 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/MimeUtils.java | 4 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 3613802aa..4e959a868 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -351,10 +351,11 @@ public class FileBackend { Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage (mime=" + mime + ")"); String extension = MimeUtils.guessExtensionFromMimeType(mime); if (extension == null) { + Log.d(Config.LOGTAG, "extension from mime type was null"); extension = getExtensionFromUri(uri); } - if (extension == null) { - extension = MimeUtils.guessExtensionFromMimeType(mime); + if ("ogg".equals(extension) && type != null && type.startsWith("audio/")) { + extension = "oga"; } String filename = fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4); message.setRelativeFilePath(filename + "." + extension); @@ -376,6 +377,12 @@ public class FileBackend { cursor.close(); } } + if (filename == null) { + final List<String> segments = uri.getPathSegments(); + if (segments.size() > 0) { + filename = segments.get(segments.size() - 1); + } + } int pos = filename == null ? -1 : filename.lastIndexOf('.'); return pos > 0 ? filename.substring(pos + 1) : null; } diff --git a/src/main/java/de/pixart/messenger/utils/MimeUtils.java b/src/main/java/de/pixart/messenger/utils/MimeUtils.java index f4db070fd..e485dc88f 100644 --- a/src/main/java/de/pixart/messenger/utils/MimeUtils.java +++ b/src/main/java/de/pixart/messenger/utils/MimeUtils.java @@ -34,8 +34,8 @@ import de.pixart.messenger.entities.Transferable; * Used to implement java.net.URLConnection and android.webkit.MimeTypeMap. */ public final class MimeUtils { - private static final Map<String, String> mimeTypeToExtensionMap = new HashMap<String, String>(); - private static final Map<String, String> extensionToMimeTypeMap = new HashMap<String, String>(); + private static final Map<String, String> mimeTypeToExtensionMap = new HashMap<>(); + private static final Map<String, String> extensionToMimeTypeMap = new HashMap<>(); static { // The following table is based on /etc/mime.types data minus |