Share Whatsapp Link via Android Intent

I am trying to send a text message with a link from my Android application to chat applications such as Whatsapp or SMS.

These applications do not accept the text / html type as the Intent type, and when I use the text / plain type, my message is sent only with the subject and without the body of the message.

I have seen apps that can share links through Whatsapp, such as Chrome browser apps and Dolphin.

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")); } 
+5
source share
1 answer
 @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 the position of emailIntent.setType("text/plain"); this line and it works. you get your link in the email application for the body.but email application, but here you can only get the subject text in the Mail apps, not the messaging app, but you can get your link in the body to achieve your goal. ..

Here it is...

+3
source

Source: https://habr.com/ru/post/1200022/


All Articles