How to make a new line in the body of the letter?

I am trying to make a new line in an email element, it doesn’t work either "\ n" nor System.getProperty ("line.separator"), how can I do this? Thanks!

Intent emailIntent=new Intent(Intent.ACTION_SEND); String subject = "Your sms sent by email"; String body = "aa"+"\n"+"bb"+System.getProperty("line.separator")+"cc" ; String[] extra = new String[]{" aa@gmail.com "}; emailIntent.putExtra(Intent.EXTRA_EMAIL, extra); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(Intent.EXTRA_TEXT, body); emailIntent.setType("message/rfc822"); startActivity(emailIntent); 
+4
source share
2 answers

If your email is in HTML, try <br/>

 String body = "aa"+"<br/>"+"bb"+"<br/>"+"cc"; 

or

 String body = "aa<br/>bb<br/>cc"; 
+4
source

This is my solution for sending email:

 public static void Send(Activity activity, String subject, String message, String to, String cc, String bcc, File attachedFile, String typeAttached) { Intent email = new Intent(Intent.ACTION_SEND); email.setType("message/rfc822"); email.putExtra(Intent.EXTRA_EMAIL, new String[]{to}); email.putExtra(Intent.EXTRA_SUBJECT, subject); email.putExtra(Intent.EXTRA_TEXT, message); if(attachedFile!=null && attachedFile.exists() && !typeAttached.isEmpty()) { email.setType(typeAttached); email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachedFile)); } if(!cc.isEmpty()) email.putExtra(Intent.EXTRA_CC, new String[]{cc}); if(!bcc.isEmpty()) email.putExtra(Intent.EXTRA_BCC, new String[]{bcc}); try { activity.startActivity(Intent.createChooser(email, "Please select your mail client:")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(activity, "There is no email client installed", Toast.LENGTH_SHORT).show(); } } 

And here is an example post:

 String message = "Hello,<br/><br/>this is a test message!"; 

I hope I helped you!

+3
source

Source: https://habr.com/ru/post/1483102/


All Articles