如何在电子邮件正文中创建换行符?

时间:2013-05-28 08:00:33

标签: android

我尝试在电子邮件正文中创建一个换行符,它不能用于“\ n”或System.getProperty(“line.separator”),我该怎么办?谢谢!

        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);

2 个答案:

答案 0 :(得分:4)

如果您的电子邮件是HTML格式,请尝试<br/>

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

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

答案 1 :(得分:3)

这是我发送电子邮件的解决方案:

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();
    }
}

这是一个示例消息:

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

我希望我能帮到你!