如何设置文本的超链接并通过电子邮件发送

时间:2017-12-06 11:57:38

标签: android email android-intent hyperlink

我有以下文字,想通过电子邮件发送超链接。

String id1String =" XES&#34 ;;

String id2String =" ZX02&#34 ;;

String appLink =" myapp:// myhost / myaction?id1 =" + id1String +"& id2 =" + id2String;

我使用了以下代码,但没有使用。

    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.setType("text/html");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
    emailIntent.putExtra(Intent.EXTRA_CC, CC);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(appLink));

    try {
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        finish();
        Log.i("Finished send email...", "");
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
    }

1 个答案:

答案 0 :(得分:0)

您可以在电子邮件意图中使用html文本作为正文。

 public void mailIntent() {
    String linkUrl = "www.stackoverflow.com";
    String body = "<a href=\"" + linkUrl + "\">" + linkUrl+ "</a>";
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.setType("text/html");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, "fdads");
    emailIntent.putExtra(Intent.EXTRA_CC, "");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
    try {
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        finish();
        Log.i("Finished send email...", "");
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
    }
}