如何将HTML文本共享到WhatsApp意图

4

我想通过 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应用程序没有显示在意图选择器列表中。

有人可以给我建议解决方案吗?


你搞定了吗? - Swaminathan V
3个回答

3

试试这个

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 - Vijay

0

请在您的代码中更改此内容,并告诉我是否有帮助,

sendIntent.setType("*/*");

-3

你应该使用,例如

https://api.whatsapp.com/send?text=https://www.example.com

在意图中打开URL。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接