diff --git a/src/org/thoughtcrime/securesms/RoutingActivity.java b/src/org/thoughtcrime/securesms/RoutingActivity.java index d89fa6c8ae..687665d7fe 100644 --- a/src/org/thoughtcrime/securesms/RoutingActivity.java +++ b/src/org/thoughtcrime/securesms/RoutingActivity.java @@ -2,7 +2,7 @@ package org.thoughtcrime.securesms; import android.content.Intent; import android.net.Uri; -import android.os.Build; +import android.webkit.MimeTypeMap; import org.thoughtcrime.securesms.crypto.MasterSecretUtil; import org.thoughtcrime.securesms.database.DatabaseFactory; @@ -228,24 +228,39 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity { private ConversationParameters getConversationParametersForShareAction() { String type = getIntent().getType(); - String draftText = null; + String draftText = getIntent().getStringExtra(Intent.EXTRA_TEXT); Uri draftImage = null; Uri draftAudio = null; Uri draftVideo = null; - if ("text/plain".equals(type)) { - draftText = getIntent().getStringExtra(Intent.EXTRA_TEXT); - } else if (type != null && type.startsWith("image/")) { - draftImage = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); + Uri streamExtra = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); + + if (streamExtra != null) { + type = getMimeType(streamExtra); + } + + if (type != null && type.startsWith("image/")) { + draftImage = streamExtra; } else if (type != null && type.startsWith("audio/")) { - draftAudio = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); + draftAudio = streamExtra; } else if (type != null && type.startsWith("video/")) { - draftVideo = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); + draftVideo = streamExtra; } return new ConversationParameters(-1, null, draftText, draftImage, draftAudio, draftVideo); } + private String getMimeType(Uri uri) { + String type = getContentResolver().getType(uri); + + if (type == null) { + String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString()); + type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + } + + return type; + } + private ConversationParameters getConversationParametersForInternalAction() { long threadId = getIntent().getLongExtra("thread_id", -1); Recipients recipients = getIntent().getParcelableExtra("recipients");