为什么它会抛出错误并提示我链接为空,即使链接存在?当我单独使用 launch (url) 时,链接打开没有任何问题。
String StateUrl = 'View App' ;
var url = 'https://www.youtube.com/watch?v=-k0IXjCHObw' ;
body: Column(
children: [
Text(StateUrl),
Center(
child: ElevatedButton.icon(
onPressed: () async{
try {
await canLaunch(url) ?
await launch(url):
throw 'Error';
} catch(e){
setState(() {
StateUrl = e.toString() ;
});
}
},
icon: const Icon(FontAwesomeIcons.link),
label: const Text('View Url')
),
),
],
),
Run Code Online (Sandbox Code Playgroud)
执行热重载:
D/EGL_emulation(17669): app_time_stats: avg=17852.65ms min=658.78ms max=35046.52ms count=2 I/UrlLauncher(17669): https://www.youtube.com/watch?v=-k0IXjCHObw的组件名称 为空 D/EGL_emulation(17669): app_time_stats: avg=8279.72ms min=8279.72ms max=8279.72ms count=1
Cươ*_*yễn 19
通过链接可以通过其他应用程序(例如 YouTube、电子表格、文档)进行处理...
从 android 11 (API 30) 及以上版本您必须添加此权限AndroidManifest.xml
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
Run Code Online (Sandbox Code Playgroud)
或者询问您需要什么:
<queries>
<package android:name="net.com.example" /> // your android package name
</queries>
Run Code Online (Sandbox Code Playgroud)
更新: 对于 QUERY_ALL_PACKAGES,您在发布应用程序时需要向 Google Play 方面解释。
为了避免这种情况,您需要查询您需要的内容:
package
, intent
...
请参考: https: //developer.android.com/training/package-visibility/declaring
小智 16
尝试使用
await launch(url);
而不是
if (await canLaunch(url)) { print("launching $url"); await launch(url); } else { throw 'Could not launch maps'; }
canLaunch(url) 函数似乎有问题
归档时间: |
|
查看次数: |
31617 次 |
最近记录: |