From fe86f757f0e5897ad3c12fc229176f0ce8603f57 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 4 Sep 2018 10:33:27 +0000 Subject: [PATCH] Fixed send-to Fixes #63 --- app/src/main/AndroidManifest.xml | 12 ++++- .../eu/faircode/email/ActivityCompose.java | 45 ++++++++++--------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e24c4048..a58fb8ce 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -62,12 +62,22 @@ android:parentActivityName=".ActivityView"> - + + + + + + + + + + + diff --git a/app/src/main/java/eu/faircode/email/ActivityCompose.java b/app/src/main/java/eu/faircode/email/ActivityCompose.java index 587b5f9a..5b8c0125 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCompose.java +++ b/app/src/main/java/eu/faircode/email/ActivityCompose.java @@ -49,40 +49,45 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB if (getSupportFragmentManager().getFragments().size() == 0) { Bundle args; - if (Intent.ACTION_SEND.equals(getIntent().getAction()) || - Intent.ACTION_SENDTO.equals(getIntent().getAction()) || - Intent.ACTION_SEND_MULTIPLE.equals(getIntent().getAction())) { + Intent intent = getIntent(); + String action = intent.getAction(); + if (Intent.ACTION_VIEW.equals(action) || + Intent.ACTION_SENDTO.equals(action) || + Intent.ACTION_SEND.equals(action) || + Intent.ACTION_SEND_MULTIPLE.equals(action)) { args = new Bundle(); - args.putString("action", "new"); args.putLong("account", -1); - if (getIntent().hasExtra(Intent.EXTRA_EMAIL)) - args.putString("to", TextUtils.join(", ", getIntent().getStringArrayExtra(Intent.EXTRA_EMAIL))); + Uri uri = intent.getData(); + if (uri != null && "mailto".equals(uri.getScheme())) + args.putString("to", uri.getSchemeSpecificPart()); + + if (intent.hasExtra(Intent.EXTRA_EMAIL)) + args.putString("to", TextUtils.join(", ", intent.getStringArrayExtra(Intent.EXTRA_EMAIL))); - if (getIntent().hasExtra(Intent.EXTRA_CC)) - args.putString("cc", TextUtils.join(", ", getIntent().getStringArrayExtra(Intent.EXTRA_CC))); + if (intent.hasExtra(Intent.EXTRA_CC)) + args.putString("cc", TextUtils.join(", ", intent.getStringArrayExtra(Intent.EXTRA_CC))); - if (getIntent().hasExtra(Intent.EXTRA_BCC)) - args.putString("bcc", TextUtils.join(", ", getIntent().getStringArrayExtra(Intent.EXTRA_BCC))); + if (intent.hasExtra(Intent.EXTRA_BCC)) + args.putString("bcc", TextUtils.join(", ", intent.getStringArrayExtra(Intent.EXTRA_BCC))); - if (getIntent().hasExtra(Intent.EXTRA_SUBJECT)) - args.putString("subject", getIntent().getStringExtra(Intent.EXTRA_SUBJECT)); + if (intent.hasExtra(Intent.EXTRA_SUBJECT)) + args.putString("subject", intent.getStringExtra(Intent.EXTRA_SUBJECT)); - if (getIntent().hasExtra(Intent.EXTRA_TEXT)) - args.putString("body", getIntent().getStringExtra(Intent.EXTRA_TEXT)); // Intent.EXTRA_HTML_TEXT + if (intent.hasExtra(Intent.EXTRA_TEXT)) + args.putString("body", intent.getStringExtra(Intent.EXTRA_TEXT)); // Intent.EXTRA_HTML_TEXT - if (getIntent().hasExtra(Intent.EXTRA_STREAM)) - if (Intent.ACTION_SEND_MULTIPLE.equals(getIntent().getAction())) - args.putParcelableArrayList("attachments", getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM)); + if (intent.hasExtra(Intent.EXTRA_STREAM)) + if (Intent.ACTION_SEND_MULTIPLE.equals(action)) + args.putParcelableArrayList("attachments", intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM)); else { ArrayList uris = new ArrayList<>(); - uris.add((Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM)); + uris.add((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)); args.putParcelableArrayList("attachments", uris); } - } else - args = getIntent().getExtras(); + args = intent.getExtras(); FragmentCompose fragment = new FragmentCompose(); fragment.setArguments(args);