繁体   English   中英

通过Android Intent发送链接到Whatsapp

[英]Send link to Whatsapp via Android Intent

我正在尝试从我的android应用程序发送带有链接的文本消息到聊天应用程序,如Whatsapp或SMS消息。

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

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

这是我的代码:

    @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"); 这条线,它的工作原理。 您可以在邮件应用程序正文电子邮件应用程序主体中获得链接。但是在这里,您只能在邮件应用程序中获得主题文本,而在邮件应用程序中无法获得主题文本,但是您可以在正文中获得链接,从而实现目标...

而已...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM