flutter_mailer
flutter_mailer copied to clipboard
Attachments not working: java.lang.ClassCastException: android.text.SpannableStringBuilder cannot be cast to java.util.ArrayList
Sending attachments broke recently:
I/ViewRootImpl@477a313[MainActivity](32228): ViewPostIme pointer 1
I/flutter (32228): /data/user/0/com.pestscope.pestscopemobile/cache117490004--13.pdf
W/NetworkRequest(32228): No App Check token for request.
2
I/System.out(32228): (HTTPLog)-Static: isSBSettingEnabled false
I/flutter (32228): Bytes loaded:7583132
W/Bundle (32228): Key android.intent.extra.TEXT expected ArrayList<CharSequence> but value was a android.text.SpannableStringBuilder. The default value <null> was returned.
W/Bundle (32228): Attempt to cast generated internal exception:
W/Bundle (32228): java.lang.ClassCastException: android.text.SpannableStringBuilder cannot be cast to java.util.ArrayList
W/Bundle (32228): at android.os.BaseBundle.getCharSequenceArrayList(BaseBundle.java:1343)
W/Bundle (32228): at android.os.Bundle.getCharSequenceArrayList(Bundle.java:1145)
W/Bundle (32228): at android.content.Intent.getCharSequenceArrayListExtra(Intent.java:9005)
W/Bundle (32228): at android.content.Intent.migrateExtraStreamToClipData(Intent.java:12041)
W/Bundle (32228): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1721)
W/Bundle (32228): at android.app.Activity.startActivityForResult(Activity.java:5377)
W/Bundle (32228): at android.app.Activity.startActivityForResult(Activity.java:5335)
W/Bundle (32228): at com.dataxad.flutter_mailer.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:73)
W/Bundle (32228): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
W/Bundle (32228): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
W/Bundle (32228): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:865)
W/Bundle (32228): at android.os.MessageQueue.nativePollOnce(Native Method)
W/Bundle (32228): at android.os.MessageQueue.next(MessageQueue.java:335)
W/Bundle (32228): at android.os.Looper.loop(Looper.java:206)
W/Bundle (32228): at android.app.ActivityThread.main(ActivityThread.java:8595)
W/Bundle (32228): at java.lang.reflect.Method.invoke(Native Method)
W/Bundle (32228): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
W/Bundle (32228): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
I/ViewRootImpl@477a313[MainActivity](32228): MSG_WINDOW_FOCUS_CHANGED 0 1
traced error to Android 4 bug: https://stackoverflow.com/questions/15776416/java-lang-classcastexception-android-text-spannablestringbuilder-cannot-be-cast
can you provide more context? how did does it break?
that error message is unfortunately the same as with #13 / cordova-plugin-email although annoying has been there since forever and does not crash the app.
So basically, when calling FlutterMailer with link to attachment it fails. The email body will be empty and no attachment after I push though.
final MailOptions mailOptions = MailOptions(
body: body,
subject: subject,
recipients: [scoutReport.sendTo],
isHTML: true,
bccRecipients: [],
ccRecipients: [],
attachments: [
pdfFile.path,
],
);
// open emailer
FlutterMailer.send(mailOptions).then((_) {});
I narrowed it down to the first setting of intent:
I/flutter (17760): Using local cached file:/data/user/0/com.pestscope.pestscopemobile/app_flutter/Reports/-94741-1-11.pdf
I/flutter (17760): /data/user/0/com.pestscope.pestscopemobile/cache-94741-1-11.pdf
W/Bundle (17760): Key android.intent.extra.TEXT expected ArrayList<CharSequence> but value was a android.text.SpannableStringBuilder. The default value
So it does not crash app but makes FlutterMailer unusable to send attachments. In the links I provided there are some workarounds proposed.
I am seeing this issue and the workarounds are Java-specific. The issue is appearing on the newest versions of Android as well.
any solution??