In various Android applications, I use the following code to show an application chooser for email and, after the user has decided for one of the apps, insert a predefined text into the email form:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sample subject");
String contentStr = "";
for (Object o : mArrayList) { // mArrayList: ArrayList<Object>
content = contentStr+o.toString()+"\n";
}
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, backupStr);
startActivity(Intent.createChooser(emailIntent, "Choose application"));
In the for-loop, the objects' string output is concatenated with the temporary string "contentStr". After every object, there should be a line break ("\n").
So when I test this code on my phone, it works fine and every single object has its own line.
But users report that their email application (Android standard as well) puts everything in one line and ignores the line breaks.
So am I doing anything wrong? Or can I just ignore this bug report as its not an issue which the developer can solve?
2 potential leads :
<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/>"););
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With