Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch whatsapp and facebook messenger window from Flutter to point to a specific contact?

Using url_launcher I can open phone to call a number.

 var phone = "+123456789";
 launch("tel://$phone");

How can I do the same for facebook messenger and whatsapp?

like image 235
Tree Avatar asked Jun 04 '18 02:06

Tree


1 Answers

I found the solution.

To open whatsapp:

var whatsappUrl ="whatsapp://send?phone=$phone";
await canLaunch(whatsappUrl)? launch(whatsappUrl):print("open whatsapp app link or do a snackbar with notification that there is no whatsapp installed");

To open messenger or facebook:

First get shortened url

If your facebook profile is facebook.com/yourName facebook url would be fb.me/yourName and messenger url would be m.me/yourName

then you do launch("http://$messengerUrl");

Facebook website will automatically open the link in the app even though it goes trough URL browser. If there is no app installed, it will go to the app/play store

like image 197
Tree Avatar answered Sep 25 '22 22:09

Tree