Better share intent handling.

1) Guess mime type from share intent EXTRA_STREAM uri.

2) Always include EXTRA_TEXT (if present)
This commit is contained in:
Marek Wehmer 2014-04-20 15:54:16 +02:00 committed by Moxie Marlinspike
parent 16764f74fe
commit 9b82411c3d

View File

@ -2,7 +2,7 @@ package org.thoughtcrime.securesms;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.webkit.MimeTypeMap;
import org.thoughtcrime.securesms.crypto.MasterSecretUtil; import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
@ -228,24 +228,39 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
private ConversationParameters getConversationParametersForShareAction() { private ConversationParameters getConversationParametersForShareAction() {
String type = getIntent().getType(); String type = getIntent().getType();
String draftText = null; String draftText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
Uri draftImage = null; Uri draftImage = null;
Uri draftAudio = null; Uri draftAudio = null;
Uri draftVideo = null; Uri draftVideo = null;
if ("text/plain".equals(type)) { Uri streamExtra = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
draftText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
} else if (type != null && type.startsWith("image/")) { if (streamExtra != null) {
draftImage = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); type = getMimeType(streamExtra);
}
if (type != null && type.startsWith("image/")) {
draftImage = streamExtra;
} else if (type != null && type.startsWith("audio/")) { } else if (type != null && type.startsWith("audio/")) {
draftAudio = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); draftAudio = streamExtra;
} else if (type != null && type.startsWith("video/")) { } else if (type != null && type.startsWith("video/")) {
draftVideo = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); draftVideo = streamExtra;
} }
return new ConversationParameters(-1, null, draftText, draftImage, draftAudio, draftVideo); 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() { private ConversationParameters getConversationParametersForInternalAction() {
long threadId = getIntent().getLongExtra("thread_id", -1); long threadId = getIntent().getLongExtra("thread_id", -1);
Recipients recipients = getIntent().getParcelableExtra("recipients"); Recipients recipients = getIntent().getParcelableExtra("recipients");