flutter 分享到whatsapp

Android11及以上:
在Manifest.xml中添加以下内容

    <queries>
        <package android:name="com.whatsapp" />
    </queries>

ios:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>whatsapp</string>
</array>

flutter :
需要 url_launcher

_launchWhatsapp() async {
//直接对指定号码发送消息
// 参考: https://api.whatsapp.com/send?phone=$phone&text=${URLEncoder.encode(message, "UTF-8")}
//  const url = 'whatsapp://send?phone=$phone';
const url = "https://wa.me/?text=Your Message here";
var encoded = Uri.encodeFull(url);

if (await canLaunch(encoded )) {
  await launch(encoded );
} else {
  throw 'Could not launch $url';
}

猜你喜欢

转载自blog.csdn.net/u011272795/article/details/108876913