flutter:url_launcher打开浏览器时报错 PlatformException(channel-error, Unable to establish connection on channel:
一,报错信息:
E/flutter (20255): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.url_launcher_android.UrlLauncherApi.openUrlInApp"., null, null)
E/flutter (20255): #0 UrlLauncherApi.openUrlInApp (package:url_launcher_android/src/messages.g.dart:198:7)
E/flutter (20255): <asynchronous suspension>
E/flutter (20255): #1 UrlLauncherAndroid.launchUrl (package:url_launcher_android/url_launcher_android.dart:100:19)
E/flutter (20255): <asynchronous suspension>
E/flutter (20255): #2 _CallPhonePageState._launchUrl (package:demo3/pages/CallPhonePage.dart:18:10)
E/flutter (20255): <asynchronous suspension>
E/flutter (20255):
二,解决:
原代码:
//打开游览器
Future<void> _launchUrl(String url) async {
final Uri _url = Uri.parse(url);
if (!await launchUrl(_url)) {
throw Exception('Could not launch $_url');
}
}
android需要增加权限:
编辑android/app/src/main/AndoridManifest.xml
在queries一项中增加:
<!-- If your app checks for SMS support -->
<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>
<!-- If your application checks for inAppBrowserView launch mode support -->
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
说明:增加support后,关闭运行的app,重新运行即可生效
浙公网安备 33010602011771号