From 59ba5634adf0b4b5f7cf1d399eb01d6ef29dc5e8 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 28 Oct 2018 07:27:22 +0000 Subject: [PATCH] Prevent crash --- .../eu/faircode/email/ActivityCompose.java | 69 ++++++++++++------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityCompose.java b/app/src/main/java/eu/faircode/email/ActivityCompose.java index 47e3f0c2..1a5d8485 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCompose.java +++ b/app/src/main/java/eu/faircode/email/ActivityCompose.java @@ -58,31 +58,54 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager. args.putLong("account", -1); 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 (intent.hasExtra(Intent.EXTRA_CC)) - args.putString("cc", TextUtils.join(", ", intent.getStringArrayExtra(Intent.EXTRA_CC))); - - if (intent.hasExtra(Intent.EXTRA_BCC)) - args.putString("bcc", TextUtils.join(", ", intent.getStringArrayExtra(Intent.EXTRA_BCC))); - - if (intent.hasExtra(Intent.EXTRA_SUBJECT)) - args.putString("subject", intent.getStringExtra(Intent.EXTRA_SUBJECT)); - - if (intent.hasExtra(Intent.EXTRA_TEXT)) - args.putString("body", intent.getStringExtra(Intent.EXTRA_TEXT)); // Intent.EXTRA_HTML_TEXT + if (uri != null && "mailto".equals(uri.getScheme())) { + String to = uri.getSchemeSpecificPart(); + if (to != null) + args.putString("to", to); + } + + if (intent.hasExtra(Intent.EXTRA_EMAIL)) { + String[] to = intent.getStringArrayExtra(Intent.EXTRA_EMAIL); + if (to != null) + args.putString("to", TextUtils.join(", ", to)); + } + + if (intent.hasExtra(Intent.EXTRA_CC)) { + String[] cc = intent.getStringArrayExtra(Intent.EXTRA_CC); + if (cc != null) + args.putString("cc", TextUtils.join(", ", cc)); + } + + if (intent.hasExtra(Intent.EXTRA_BCC)) { + String[] bcc = intent.getStringArrayExtra(Intent.EXTRA_BCC); + if (bcc != null) + args.putString("bcc", TextUtils.join(", ", bcc)); + } + + if (intent.hasExtra(Intent.EXTRA_SUBJECT)) { + String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); + if (subject != null) + args.putString("subject", subject); + } + + if (intent.hasExtra(Intent.EXTRA_TEXT)) { + String body = intent.getStringExtra(Intent.EXTRA_TEXT); // Intent.EXTRA_HTML_TEXT + if (body != null) + args.putString("body", body); + } 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) intent.getParcelableExtra(Intent.EXTRA_STREAM)); - args.putParcelableArrayList("attachments", uris); + if (Intent.ACTION_SEND_MULTIPLE.equals(action)) { + ArrayList uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); + if (uris != null) + args.putParcelableArrayList("attachments", uris); + } else { + Uri stream = intent.getParcelableExtra(Intent.EXTRA_STREAM); + if (stream != null) { + ArrayList uris = new ArrayList<>(); + uris.add((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)); + args.putParcelableArrayList("attachments", uris); + } } } else args = intent.getExtras();