简体   繁体   English

通过Android Intent发送链接到Whatsapp

[英]Send link to Whatsapp via Android Intent

I'm trying to send a text message with a link from my android app to chat applications like Whatsapp or SMS message. 我正在尝试从我的android应用程序发送带有链接的文本消息到聊天应用程序,如Whatsapp或SMS消息。

These apps don't accept text/html type as an Intent type and when I'm using text/plain type my message is being sent with the subject only and without the message's body. 这些应用程序不接受text / html类型作为Intent类型,当我使用text / plain类型时,我发送的消息仅包含主题,而没有消息的正文。

I've seen apps that can share links via Whatsapp like Chrome and Dolphin Browser apps. 我见过可以通过Whatsapp共享链接的应用程序,例如Chrome和Dolphin Browser应用程序。

Here is my code: 这是我的代码:

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

here i just change position of emailIntent.setType("text/plain"); 在这里,我只是更改emailIntent.setType("text/plain"); this line and it works. 这条线,它的工作原理。 you get your link in messaging app body email app body.but here you can get subject text only in Mail apps not in messaging app but you can get your link in body so achive your goal... 您可以在邮件应用程序正文电子邮件应用程序主体中获得链接。但是在这里,您只能在邮件应用程序中获得主题文本,而在邮件应用程序中无法获得主题文本,但是您可以在正文中获得链接,从而实现目标...

Thats it... 而已...

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

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