【问题标题】:How to share Html text to whatsapp intent如何将 Html 文本分享到 whatsapp 意图
【发布时间】:2016-07-04 17:12:30
【问题描述】:

我想通过whatsapp intent 分享Html 文本。我写的代码如下。

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                sharingIntent.setType("text/html");
                sharingIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(new StringBuilder()
                .append("<p><b>Some Content</b></p>")
                .append("<small><p>More content</p></small>")
                .toString()));
                this.getContext().startActivity(Intent.createChooser(sharingIntent,"Share using"));

但 whatsapp 应用程序未显示在 Intent 选择器列表中。

谁能给我建议解决方案?

【问题讨论】:

  • 你成功了吗

标签: android android-intent whatsapp


【解决方案1】:

试试这个

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setPackage(com.whatsapp);
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(new StringBuilder()
    .append("<p><b>Some Content</b></p>")
    .append("<small><p>More content</p></small>")
    .toString()));
sendIntent.setType("text/html");
context.startActivity(sendIntent);

【讨论】:

  • 我最初仅尝试使用此代码,但在 sendIntent.setType("text/html"); android.content.ActivityNotFoundException
【解决方案2】:

请在您的代码中更改此内容,如果对您有帮助,请告诉我,

sendIntent.setType("*/*");

【讨论】:

    猜你喜欢
    • 2018-09-04
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 2021-11-12
    相关资源
    最近更新 更多