Flutter应用打开网页遇net:ERR_CACHE_MISS错误,添加Intent Filter后无法启动
Flutter应用打开网页报错net:ERR_CACHE_MISS及启动异常解决
问题描述
使用Flutter开发的应用点击网页链接时,浏览器打开后报错:"Unable to load page https://… because of net:ERR_CACHE_MISS"。尝试添加特定intent-filter后,应用可安装但无法启动,部分设备仅显示应用信息。
用户现有配置
pubspec.yaml
url_launcher: ^6.1.1
AndroidManifest.xml(查询配置)
<queries> <intent> <action android:name="android.intent.action.SENDTO" /> <data android:scheme="mailto" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="https" /> </intent> </queries>
链接调用代码
Future<void> _launchUrl() async { final Uri _url = Uri.parse('https://www.google.com'); if (!await launchUrl(_url)) { throw Exception('Could not launch $_url'); } }
错误操作
添加以下intent-filter到AndroidManifest后出现启动异常:
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" /> <data android:scheme="https" /> <data android:host="www.google.com" /> </intent-filter>
环境信息
- Flutter 3.10.6(stable通道)
- Framework 版本:f468f3366c(2023-07-12)
- Engine 版本:cdbeda788a
- Dart 3.0.6,DevTools 2.23.1
解决步骤
1. 修正配置
原配置将多个action和data合并在同一个
<queries> <!-- 处理mailto链接 --> <intent> <action android:name="android.intent.action.SENDTO" /> <data android:scheme="mailto" /> </intent> <!-- 处理HTTP/HTTPS链接 --> <intent> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" /> <data android:scheme="https" /> </intent> </queries>
2. 移除冲突的intent-filter
你添加的intent-filter将应用注册为www.google.com的默认处理程序,与应用启动页的intent-filter冲突,导致系统无法识别应用入口,必须删除该配置。
3. 指定外部浏览器启动模式
调用launchUrl时明确指定用外部浏览器打开,避免缓存或应用内处理的问题:
Future<void> _launchUrl() async { final Uri _url = Uri.parse('https://www.google.com'); if (!await launchUrl( _url, mode: LaunchMode.externalApplication, )) { throw Exception('Could not launch $_url'); } }
4. 确认网络权限
确保AndroidManifest中已添加网络权限(Flutter默认会自动配置,可检查确认):
<uses-permission android:name="android.permission.INTERNET" />
内容的提问来源于stack exchange,提问作者GrzegorzJ
相关产品推荐
相关产品推荐

