通过 Android Intent 发送链接到 Whatsapp

2024-02-25

我正在尝试从我的 Android 应用程序向 Whatsapp 或短信等聊天应用程序发送带有链接的短信。

这些应用程序不接受 text/html 类型作为 Intent 类型,当我使用 text/plain 类型时,我的消息仅包含主题而没有消息正文。

我见过可以通过 Whatsapp 共享链接的应用程序,例如 Chrome 和 Dolphin 浏览器应用程序。

这是我的代码:

    @JavascriptInterface
    public void sendMessage(String trip) {
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("text/plain");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Trip from Voyajo");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("I've found a trip in Voyajo website that might be interested you, http://www.voyajo.com/viewTrip.aspx?trip=" + trip));
        startActivity(Intent.createChooser(emailIntent, "Send to friend"));
}

@JavascriptInterface
    public void sendMessage(String trip) {
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Trip from Voyajo");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("I've found a trip in Voyajo website that might be interested you, http://www.voyajo.com/viewTrip.aspx?trip=" + trip));
        emailIntent.setType("text/plain");
        startActivity(Intent.createChooser(emailIntent, "Send to friend"));
}

在这里我只是改变位置emailIntent.setType("text/plain");这条线并且有效。 您可以在消息应用程序正文中获取链接,电子邮件应用程序正文中。但在这里,您只能在邮件应用程序中获取主题文本,而不能在消息应用程序中获取主题文本,但您可以在正文中获取链接,以便实现您的目标...

就是这样...

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 Android Intent 发送链接到 Whatsapp 的相关文章

随机推荐