You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter开发:Android端无法唤起WhatsApp发消息求助

Android端无法唤起WhatsApp应用问题排查求助

我正在开发一款支持用户通过WhatsApp通讯的App,预期功能为:若用户已安装WhatsApp且URL可唤起,则直接打开外部WhatsApp应用;否则打开短信。目前该功能在iOS端运行正常,但Android端无法工作,我怀疑问题出在AndroidManifest.xml文件中,恳请帮助。

实现代码(使用url_launcher ^6.1.7)

Future<void> launchWhatsApp({required BuildContext context, required String phoneNumber}) async {
    // Phone number is in country code + number format (+11234567890)
    var androidUrlString = "https://whatsapp://send?phone=$phoneNumber&text=${Uri.parse('')}";
    var androidUrl = Uri.parse(androidUrlString);
    var iosUrlString = "https://wa.me/$phoneNumber?text=${Uri.parse('')}";
    var iosUrl = Uri.parse(iosUrlString);
    var smsUrl = Uri(scheme: 'sms', path: phoneNumber);

    // Will attempt to launch SMS message if the each platform's url cannot be launched ...
    // Show snackbar error if failed
    try {
      if (Platform.isIOS) {
        if (await canLaunchUrl(iosUrl)) { 
          await launchUrl(iosUrl, mode: LaunchMode.externalApplication); // WORKS HERE
        } else {
          await launchUrl(smsUrl);
        }
      } else {
        if (await canLaunchUrl(androidUrl)) { 
          await launchUrl(androidUrl, mode: LaunchMode.externalApplication); // DOES NOT WORK
        } else {
          await launchUrl(smsUrl);
        }
      }
    } on Exception {
      showSnackbar(context, SnackBarError.unknownError);
      return;
    }
  }

问题补充

最初未定义LaunchMode时,App会打开浏览器进入WhatsApp网页版;设置为LaunchMode.externalApplication后iOS端恢复正常,但Android端仍无效。

AndroidManifest.xml相关片段

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="my.bundle.id">
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="https" />
        </intent>
        <intent>
            <action android:name="android.intent.action.DIAL" />
            <data android:scheme="tel" />
        </intent>
        <intent>
            <action android:name="android.intent.action.SEND" />
            <data android:mimeType="*/*" />
        </intent>
    </queries>
    ...

我专门准备了一部几乎未配置的新Android手机测试该功能,不确定是否是问题根源。


内容的提问来源于stack exchange,提问作者corbiter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 07:34:56