7

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"));
}
eladzaa
  • 168
  • 1
  • 2
  • 9
  • For me (latest WhatsApp on a Nexus 5, Android 5.0), both `EXTRA_SUBJECT` and `EXTRA_TEXT` are included in the shared message, in the form "Subject - Extra text". What I did: use only `EXTRA_TEXT`, putting the whole message, including urls, in that. But use *plain text*, skip all HTML. – Jonik Jan 28 '15 at 12:29

1 Answers1

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

Jayesh Khasatiya
  • 2,140
  • 1
  • 14
  • 15