aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-06-16 11:46:25 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-06-16 11:46:25 +0200
commitf8b1e8098c2d94972117e1f1771f66695e583934 (patch)
tree68e32b8f2d1911e8ba258920c6924526593605eb /src/main/java/eu
parent60588af8257290fdf47e500e7ff642ee199e0cf9 (diff)
extract relevant extension from file name when processing share intent
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index db48c8b3..a9217b16 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -14,6 +14,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
+import android.provider.MediaStore;
import android.provider.OpenableColumns;
import android.system.Os;
import android.system.StructStat;
@@ -248,13 +249,33 @@ public class FileBackend {
}
public void copyFileToPrivateStorage(Message message, Uri uri) throws FileCopyException {
- Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage");
String mime = mXmppConnectionService.getContentResolver().getType(uri);
+ Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage (mime="+mime+")");
String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mime);
+ if (extension == null) {
+ extension = getExtensionFromUri(uri);
+ }
message.setRelativeFilePath(message.getUuid() + "." + extension);
copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri);
}
+ private String getExtensionFromUri(Uri uri) {
+ String[] projection = {MediaStore.MediaColumns.DATA};
+ String filename = null;
+ Cursor cursor = mXmppConnectionService.getContentResolver().query(uri, projection, null, null, null);
+ if (cursor != null) {
+ try {
+ if (cursor.moveToFirst()) {
+ filename = cursor.getString(0);
+ }
+ } finally {
+ cursor.close();
+ }
+ }
+ int pos = filename == null ? -1 : filename.lastIndexOf('.');
+ return pos > 0 ? filename.substring(pos+1) : null;
+ }
+
private void copyImageToPrivateStorage(File file, Uri image, int sampleSize) throws FileCopyException {
file.getParentFile().mkdirs();
InputStream is = null;