Permalink
Browse files

Fixed issue with plain text body coming out blank on android if there…

… is an attachment when sending email. This started out as an investigation into #1782, a class cast exception when sending email with an attachment.  This fixes the issue when there is only one attachment.  If multiple attachments are included, then the class cast exception still occurs, but it appears to be handled and just printed internally as the intent still functions correctly.  Attempts to employ the suggested workaround in that issue produced a blank message body.
  • Loading branch information...
1 parent 6395bec commit 46519a94eeb6449561bcff0acc6e6ec80e1067fd @shannah shannah committed Jan 4, 2017
Showing with 18 additions and 2 deletions.
  1. +18 −2 Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java
@@ -5046,7 +5046,7 @@ public void sendMessage(String[] recipients, String subject, Message msg) {
+ "&body=" + Uri.encode(msg.getContent())));
}else{
if (hasAttachment) {
- if(msg.getAttachments().size() > 0) {
+ if(msg.getAttachments().size() > 1) {
emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
@@ -5078,7 +5078,23 @@ public void sendMessage(String[] recipients, String subject, Message msg) {
if (msg.getMimeType().equals(Message.MIME_HTML)) {
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(msg.getContent()));
}else{
- emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());
+ /*
+ // Attempted this workaround to fix the ClassCastException that occurs on android when
+ // there are multiple attachments. Unfortunately, this fixes the stack trace, but
+ // has the unwanted side-effect of producing a blank message body.
+ // Same workaround for HTML mimetype also fails the same way.
+ // Conclusion, Just live with the stack trace. It doesn't seem to affect the
+ // execution of the program... treat it as a warning.
+ // See https://github.com/codenameone/CodenameOne/issues/1782
+ if (msg.getAttachments().size() > 1) {
+ ArrayList<String> contentArr = new ArrayList<String>();
+ contentArr.add(msg.getContent());
+ emailIntent.putStringArrayListExtra(android.content.Intent.EXTRA_TEXT, contentArr);
+ } else {
+ emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());
+
+ }*/
+ emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());
}
}

0 comments on commit 46519a9

Please sign in to comment.