【问题标题】:Android Email Intent and Linebreaks Howto?Android 电子邮件意图和换行符 Howto?
【发布时间】:2011-12-28 18:05:53
【问题描述】:

我有以下问题:

我正在通过意图发送电子邮件,并且我希望在电子邮件中进行换行。

当我尝试“setType('text/plain')”并使用 \n's 时,电子邮件应用程序不使用这些,但 Gmail 应用程序没问题。 当我设置“setType('text/html')”并使用 br 和 Html.fromHtml(emailtext) 时,电子邮件应用程序不会换行。当我不使用 Html.fromHtml(emailtext) 时,电子邮件应用会进行换行,但 Gmail 应用会将 br 显示为普通文本。

难道没有办法在 Android 电子邮件意图中进行简单的换行吗?

【问题讨论】:

    标签: android email android-intent line-breaks


    【解决方案1】:

    嗨,这段代码可能会帮助你

    String emailMessage = "<html><body><div align='left'><p>I found this information on Actor Genie and wanted to share it with you.</p><p><b>Feature </b>: "
                            + filmName
                            + "</p><p><b>Casting Director</b>: "
                            + casting
                            + "</p><p><b>Distributor</b>: "
                            + distributor
                            + "<p><b>Story Line</b>: "
                            + storyLine
                            + "</p><p>For up to the date casting info get <a href='http://www.actorgenie.com/'>Actor Genie</a></p></div></body></html>";
                    Intent emailIntent = new Intent(
                            android.content.Intent.ACTION_SEND);
                    // emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
                    emailIntent.setType("text/html");
                    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                            emailSubject);
                    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html
                            .fromHtml(emailMessage));
                    startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                    finish();
    

    【讨论】:

    • 不,这并没有改变任何东西。这基本上就是我正在做的,我只是没有这些 html+body 部分。似乎当我执行 Html.fromHtml 时,Email-app 不再使用这个 html-tags。顺便说一句,它是三星 Galaxy S2。
    • 它对我有用,我在三星 ace 和 HTC Desire 中测试过
    【解决方案2】:

    以此强制 Gmail

    Intent emailIntent = new Intent(Intent.ACTION_VIEW);
    emailIntent.setClassName("com.google.android.gm",
                         "com.google.android.gm.ComposeActivityGmail");
    startActivity(emailIntent);
    

    在您的文本代码中使用 \n。

     emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hello \n World");
    

    【讨论】:

    • 我不想强制使用 gmail。这是一款商业应用程序,因此应该允许人们使用他们想要的任何电子邮件客户端。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多