taljacobson / flutter_mailer

A wrapper on top of MFMailComposeViewController from iOS and Mail Intent on android
MIT License
46 stars 35 forks source link

Key android.intent.extra.TEXT expected ArrayList<CharSequence> but value was a java.lang.String #36

Open ttencate opened 3 years ago

ttencate commented 3 years ago

Getting this error:

W/Bundle  (25875): Key android.intent.extra.TEXT expected ArrayList<CharSequence> but value was a java.lang.String.  The default value <null> was returned.
W/Bundle  (25875): Attempt to cast generated internal exception:
W/Bundle  (25875): java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList
W/Bundle  (25875):  at android.os.BaseBundle.getCharSequenceArrayList(BaseBundle.java:1139)
W/Bundle  (25875):  at android.os.Bundle.getCharSequenceArrayList(Bundle.java:1000)
W/Bundle  (25875):  at android.content.Intent.getCharSequenceArrayListExtra(Intent.java:6355)
W/Bundle  (25875):  at android.content.Intent.migrateExtraStreamToClipData(Intent.java:9092)
W/Bundle  (25875):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)
W/Bundle  (25875):  at android.app.Activity.startActivityForResult(Activity.java:4269)
W/Bundle  (25875):  at android.app.Activity.startActivityForResult(Activity.java:4227)
W/Bundle  (25875):  at com.dataxad.flutter_mailer.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:73)
W/Bundle  (25875):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
W/Bundle  (25875):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
W/Bundle  (25875):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:693)
W/Bundle  (25875):  at android.os.MessageQueue.nativePollOnce(Native Method)
W/Bundle  (25875):  at android.os.MessageQueue.next(MessageQueue.java:323)
W/Bundle  (25875):  at android.os.Looper.loop(Looper.java:136)
W/Bundle  (25875):  at android.app.ActivityThread.main(ActivityThread.java:6128)
W/Bundle  (25875):  at java.lang.reflect.Method.invoke(Native Method)
W/Bundle  (25875):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
W/Bundle  (25875):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Here's the minimal code:

  final response = await FlutterMailer.send(MailOptions(
    recipients: <String>['nobody@example.com'],
    subject: 'hello',
    body: 'world',
    attachments: <String>['/data/user/0/com.example.app/cache/log.txt'],
  ));

It seems that the intent does get sent, but not properly: the app chooser popup includes non-email apps such as Discord and WhatsApp. After selecting Gmail, everything is filled out as intended, including the attachment.

When I omit the attachment, the above error does not happen, and the app chooser only contains the apps Gmail and Email as expected.

When I set isHTML: true, the error reports that the value was an android.text.SpannableStringBuilder instead of a java.lang.String.

I believe this is caused by the intent's action being changed here from ACTION_SEND to ACTION_SEND_MULTIPLE, which expects EXTRA_TEXT and EXTRA_STREAM to be arrays instead of single strings.

Flutter doctor output (including device info and Android version):

[✓] Flutter (Channel dev, 1.24.0-10.1.pre, on Linux, locale en_US.UTF-8)
    • Flutter version 1.24.0-10.1.pre at /home/thomas/flutter
    • Framework revision 405c85fe7e (5 days ago), 2020-11-13 21:22:10 -0800
    • Engine revision bd390c0310
    • Dart version 2.12.0 (build 2.12.0-29.7.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /opt/android-sdk
    • Platform android-29, build-tools 29.0.3
    • ANDROID_HOME = /opt/android-sdk
    • ANDROID_SDK_ROOT = /opt/android-sdk
    • Java binary at: /usr/lib/jvm/default/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_265-b01)
    • All Android licenses accepted.

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] IntelliJ IDEA Community Edition (version 2020.2)
    • IntelliJ at /usr/share/jetbrains-idea-ce
    • Flutter plugin version 49.0.4
    • Dart plugin version 202.7206

[✓] Connected device (1 available)
    • FP2 (mobile) • 1e95f6f3 • android-arm • Android 7.1.2 (API 25)

! Doctor found issues in 1 category.