外部共享android

时间:2016-11-11 13:12:02

标签: android html

您好我用以分享以下内容

<html>
 <head>
  <style type="text/css"> 
   @font-face { 
       font-family: MyFont; 
       src: url("file:///android_asset/fonts/opensans_regular.ttf") 
   } 
   body { 
       font-family: MyFont; 
       text-align: justify; 
       color: #000000; 
   } 
  </style> 
 </head>
  <body><font size=6>
<h3><strong>Journée Do it yourself !</strong></h3>
<p><strong>Samedi 5 novembre</strong></p>
<p>Le “Do It Yourself” est le mouvement du “faire soi-même” regroupant celles et ceux qui, inventifs, bricoleurs et débrouillards, souhaitent s’exprimer, expérimenter et partager leur savoir-faire.<br />
<strong>Vous voulez animer des ateliers créatifs à la médiathèque ?</strong> Cette journée est pour vous ! Couture, tricot, customisation, récup, Fab’lab, imprimante 3D… toutes les créations sont possibles !<br />
<strong>Alors n’hésitez pas à nous solliciter avant le 30 septembre pour participer à cet événement inédit en venant partager votre passion ou votre savoir-faire.</strong><br />
Contact : Sophie Bourgeois</p>
<ul>
<li>01.34.58.12.19</li>
<li><a href="mailto:sophiebourgeois@velizy-villacoublay.fr">sophiebourgeois@velizy-villacoublay.fr</a></li>
</ul>
  </font></body>
</html>

使用以下代码

访问外部应用
  sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body)+"\n "+appendContent);

我用来在webview和外部共享中加载这个正文字符串。但两种格式都有所不同。我想在外部应用程序中分享它,就像我在webview中看到的格式一样。你能建议我这么做吗?提前谢谢。

2 个答案:

答案 0 :(得分:0)

您可以使用它来发送文本

// SendEmail是电子邮件发送Btn ID

protected void sendEmail() { 
    Log.i("Send email", "");
    String[] TO = {""};
    String[] CC = {""};
    Intent emailIntent = new Intent(Intent.ACTION_SEND);

    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.setType("text/plain");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
    emailIntent.putExtra(Intent.EXTRA_CC, CC);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, " Your Subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, " Your Text Here");
    emailIntent.setType("message/rfc822");

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

答案 1 :(得分:0)

  

我用以下代码

与外部应用分享以下内容....

您正在使用Html.fromHtml()。这支持有限数量的HTML标记。它不支持样式表和Web字体。此外,仅在Android 7.0+上可能会处理列表。

另外,在您添加appendContent后,您将不再拥有有效的HTML,因为您的文字位于</html>标记之外。

因此,请专注于使用格式非常有限的有效HTML。 This blog post of mine列出了Android 7.0之前Html.fromHtml()支持的大部分代码。

相关问题