繁体   English   中英

打开 WhatsApp 等应用程序以共享文本时出错:Flutter

[英]Error opening Apps like WhatsApp to share text: Flutter

我正在尝试从我的 flutter 应用程序内部打开诸如 WhatsApp、Twitter 和 Facebook 之类的应用程序,但我收到 ZE6B391A8D2C4D45903DZ 方案3 错误。 请帮忙! 我正在使用的代码是

                      child: ElevatedButton(
                        onPressed: () async {
                          String url =
                              "https://api.whatsapp.com/send?text=Hello there!";
                          var encoded = Uri.encodeFull(url);
                          Uri whatsAppUri = Uri.parse(encoded);
                          if (await canLaunchUrl(whatsAppUri)) {
                            await launchUrl(whatsAppUri);
                          }
                        },

我收到以下错误屏幕- 按下按钮时的错误屏幕

请帮我找到正确的方法和URL。 另外请帮助我处理 Twitter 和 Facebook 因为我也需要使用它们。 谢谢你!

用这个:

const url = "whatsapp://send?text=Hello World!"

或者

const url = "https://wa.me/?text=Hello World!";

如果您使用 ios,请将其添加到您的info.plist

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

对于 facebook:

const url = "fb://facewebmodal/f?href=$username";

对于 twitter:

const url = "https://twitter.com/username";

最后但并非最不重要的一点是确保您添加了正确的配置,您可以从这里找到更多信息

您可以使用以下代码:

String url() {
    if (Platform.isAndroid) {
      return "https://wa.me/$phone/?text=Hello there!";
    } else {
      return "https://api.whatsapp.com/send?phone=$phone=Hello there!}";
    }
  }

String url = url();
var encoded = Uri.encodeFull(url);
                          Uri whatsAppUri = Uri.parse(encoded);
                          if (await canLaunchUrl(whatsAppUri)) {
                            await launchUrl(whatsAppUri);
                          }

在 $phone 的地方,您可以写下您要发送的用户的电话号码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM