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';
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 点我我会动 设计师:上身试试 返回首页