android - 如何从我的应用程序发送带有下划线或粗体文本的邮件?

标签 android email

我的代码:

String html = "<html><body><b<bold</b><u>underline</u></body></html>";
Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT,
Html.fromHtml(html));
startActivity(Intent.createChooser(intent, "Send Email"));

结果是普通文本。有没有办法让这段文字加粗并加下划线?

最佳答案

根据 this documentation,您不能将 text/html 类型与 Intent.EXTRA_TEXT 一起使用.您是否尝试过 EXTRA_STREAM

另一方面,粗体标记中存在 HTML 语法错误:

String html = "<html><body><b<bold</b><u>underline</u></body></html>";

应该是:

String html = "<html><body><b>bold</b><u>underline</u></body></html>";

更新:

这可能是您的默认电子邮件应用程序中的错误,如果可以,请尝试使用 Gmail 应用程序,看看会发生什么。稍微更改代码以再次选择您的默认邮件客户端:

try {
    startActivity(Intent.createChooser(intent, "Send mail"));
    Log.i("MAIL", "Finished sending email");
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(getApplicationContext(), 
    "There is no email client installed.", Toast.LENGTH_SHORT).show();
}

正如您在下图中看到的,它与 Android 框架的默认邮件应用程序一起工作。

enter image description here

例如,您是否尝试过将 Project Build Target 设置为 4.3?

enter image description here

关于android - 如何从我的应用程序发送带有下划线或粗体文本的邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21807679/

相关文章:

java - 如何在jsonobject中设置数组

android - 为 Web 和 Android 服务的 AppEngine GWT-RPC 服务

c# - 是否可以重置 ServicePointManager?

python - 电子邮件附件问题

android - 媒体记录器 : stop called in an invalid state: 1

android - 递增的秒表计时器(如倒计时计时器)

android - Material Design 中介绍的原生 SeekbarPreference

javascript - 单击电子邮件验证按钮未打开新窗口

linux - 在一个文件的行中搜索另一个文件中的部分匹配项(Mac/Linux/Unix 命令行)

laravel - 如何在电子邮件布局 Laravel 5.4 中显示两个表格?