Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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"));
}
like image 676
eladzaa Avatar asked Aug 11 '14 12:08

eladzaa


People also ask

How send WhatsApp link in Android programmatically?

Android intent system Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker: Intent sendIntent = new Intent(); sendIntent.

How do I send an HTML link on WhatsApp?

To create your own link, use https://wa.me/ where the is a full phone number in international format. Omit any zeroes, brackets or dashes when adding the phone number in international format.


1 Answers

@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...

like image 167
Jayesh Khasatiya Avatar answered Sep 28 '22 11:09

Jayesh Khasatiya