mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
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:
parent
16764f74fe
commit
9b82411c3d
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user