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

大憨熊 提交于 2020-02-02 03:31:23

问题


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?


回答1:


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




回答2:


To open the whatsapp you can use this plugin: https://pub.dartlang.org/packages/flutter_launch

1. Add this to your package's pubspec.yaml file:

dependencies:
    flutter_launch: "^0.0.2"

2. Install it

$ flutter packages get

3. Import it

import 'package:flutter_launch/flutter_launch.dart';

4. Example:

await FlutterLaunch.launchWathsApp(phone: "5534992019999", message: "Hello");

Complete example: https://pub.dartlang.org/packages/flutter_launch#-installing-tab-



来源:https://stackoverflow.com/questions/50672710/how-to-launch-whatsapp-and-facebook-messenger-window-from-flutter-to-point-to-a

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