![](/img/trans.png)
[英]Flutter: How to share PDF file to built inn apps like Whatsapp or email
[英]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.