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

使用url_launcher无法打开Stripe测试结账页,报ACTIVITY_NOT_FOUND错误

解决Flutter中url_launcher打开Stripe测试结账页时的ACTIVITY_NOT_FOUND错误

问题场景

在Flutter应用中使用url_launcher包打开Stripe测试模式的结账页面时,触发以下错误:

PlatformException(ACTIVITY_NOT_FOUND, No Activity found to handle intent {  }, null, null)

已按照pub.dev的说明在AndroidManifest.xml中添加了queries配置,具体内容如下:

<queries>
        <!-- If your app checks for SMS support -->
        <!-- Place inside the <queries> element. -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" />
        </intent>
        <!-- Place inside the <queries> element. -->
        <intent>
            <action android:name="android.support.customtabs.action.CustomTabsService" />
        </intent>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="sms" />
        </intent>
        <!-- If your app checks for call support -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="tel" />
        </intent>
</queries>

解决办法

  • 确认Stripe结账URL有效性:先打印生成的测试URL,确保是完整的https://开头的有效链接,无空值或格式错误。若URL不合法,系统无法找到对应的处理Activity。
  • 检查queries配置位置:确保<queries>标签与<application>标签同级,而非嵌套在<application>内部。Android 11+对包可见性要求严格,位置错误会导致配置失效。
  • 调整url_launcher调用逻辑:使用最新的launchUrl方法,并指定启动模式为外部应用,强制系统调用浏览器处理链接:
import 'package:url_launcher/url_launcher.dart';

// 替换为你的Stripe测试结账URL
final Uri stripeCheckoutUrl = Uri.parse('https://checkout.stripe.com/pay/cs_test_xxx');

if (await canLaunchUrl(stripeCheckoutUrl)) {
  await launchUrl(
    stripeCheckoutUrl,
    mode: LaunchMode.externalApplication,
  );
} else {
  // 处理无法打开链接的异常情况
}
  • 检查设备浏览器状态:确保测试设备或模拟器上安装了Chrome、Firefox等浏览器应用。部分精简版模拟器默认无浏览器,会导致无法处理https链接的intent。
  • 清理重建项目:执行flutter clean清除缓存,再运行flutter pub get重新拉取依赖,最后重新编译运行项目,避免缓存导致的配置不生效问题。

内容的提问来源于stack exchange,提问作者Haya Hesham Abdel-azim

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 19:52:30