您的位置:首页 > 财经 > 产业 > Flutter 使用 url_launcher的canLaunchUrl() 方法总是返回false错误

Flutter 使用 url_launcher的canLaunchUrl() 方法总是返回false错误

2024/10/5 11:11:23 来源:https://blog.csdn.net/qq_38774121/article/details/140670198  浏览:    关键词:Flutter 使用 url_launcher的canLaunchUrl() 方法总是返回false错误

Flutter 使用 url_launcher的canLaunchUrl() 方法总是返回false错误

众所周知,我们一般使用url_launcher来打开各种应用,网页,手机应用等....

但是最近发现Flutter的canLaunchUrl()方法总是返回false,这是为什么呢?

原因:

自从Android SDK 30 或 以上为了更加安全,需要在AndroidManifest.xml声明可访问包名和scheme

总的来说,现在Android也类似于IOS一样,需要事先声明打开其他APP的通道可包名了

解决办法:

以高德地图,百度地图为例:

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"package="xxxxxx"><queries><!-- 需要检查的包名 --><!-- 高德地图 --><package android:name="com.autonavi.minimap" />  <!-- 百度地图 --><package android:name="com.baidu.BaiduMap" />  <!-- Scheme匹配 --><!-- 高德地图scheme --><intent><action android:name="com.autonavi.minimap" /><data android:scheme="amap" /></intent><!-- 百度地图scheme --><intent><action android:name="com.baidu.BaiduMap" /><data android:scheme="baidumap" /></intent></queries>

声明后,canLaunchUrl()便会返回true,即可打开APP,使用其功能

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com