Send link to Whatsapp via Android Intent

邮差的信 提交于 2019-12-12 10:45:37

问题


I'm trying to send a text message with a link from my android app to chat applications like Whatsapp or SMS message.

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.

I've seen apps that can share links via Whatsapp like Chrome and Dolphin Browser apps.

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

回答1:


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



来源:https://stackoverflow.com/questions/25243143/send-link-to-whatsapp-via-android-intent

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