java.lang.ClassCastException: android.text.SpannableStringBuilder cannot be cast to java.util.ArrayList

回眸只為那壹抹淺笑 提交于 2019-12-01 03:19:20

It's down this this bug in Android 4.x

You can work around the problem for plain text emails by replacing this line in EmailComposer.java:

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);

with

ArrayList<String> extra_text = new ArrayList<String>();
extra_text.add(body);
emailIntent.putStringArrayListExtra(android.content.Intent.EXTRA_TEXT, extra_text);

But this won't work for HTML emails because Spanned (returned by Html.fromHtml) is not a subclass of Charsequence. When I tried casting the result of Html.fromHtml() to a string, the tags appeared as part of the text :-(

Also when I tried this, the body of plain text emails to appeared when using the Gmail app but it didn't appear in stock Email app - body was always blank.

Just try a different approach:

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
//emailIntent.putExtra(Intent.EXTRA_HTML_TEXT, body); //If you are using HTML in your body text

startActivity(Intent.createChooser(emailIntent, "Chooser Title"));

taken from here: Send Email Intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!