4

我尝试在电子邮件正文中添加换行符,但“\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);
4

2 回答 2

5

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

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

或者

String body = "aa<br/>bb<br/>cc";
于 2013-05-28T08:01:49.557 回答
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!";

我希望我对你有所帮助!

于 2013-05-28T08:06:17.840 回答