Email intent ignoring line-breaks in preset text (Android)
2 potential leads :
- Try with \r or \n\r instead of simply \n, or even 2 line breaks.
- Use HTML formatted line breaks (
<br>
)
Also, there is something wrong with your code in here
String contentStr = "";
for (Object o : mArrayList) { // mArrayList: ArrayList<Object>
content = contentStr+o.toString()+"\n";
}
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, backupStr);
This does not put anything in the intent, contentStr is empty, and content only contains the last object.
This is a better, shorter and more efficient method:
contentStr = TextUtils.join("\n", mArrayList);
You need replace \n
to <br/>
even you put EXTRA_TEXT
. There is my code:
final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "This\nis\na\ntest!".replace("\n", "<br/>"););