How to share Html text to whatsapp intent

爱⌒轻易说出口 提交于 2019-12-22 08:06:49

问题


I want to share Html text via whatsapp intent. The code I have written is below.

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"));

But whatsapp application is not showing in Intent chooser list.

Can anyone suggest me the solution?


回答1:


Try this

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);



回答2:


please change this in your code and let me know if it helped you,

sendIntent.setType("*/*");


来源:https://stackoverflow.com/questions/36076067/how-to-share-html-text-to-whatsapp-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!