所以我知道对于 android 版本 >= 30,你需要在清单中添加查询,但这对我来说并没有成功。我使用的是 Android 版本 29。尽管如此,我还是将这些行添加到了我的清单中。
所以我的清单看起来像这样。
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
Run Code Online (Sandbox Code Playgroud)
我设法使用下面的代码为我的机器重现该错误。尽管如此,我还是收到了这个错误:
I/UrlLauncher(10601): mailto:?subject=&body= 的组件名称为 null
在下面您可以找到 main.dart 的代码
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) …
Run Code Online (Sandbox Code Playgroud) 我使用了url_launcher包。
String query = Uri.encodeComponent(Utils.getSelectedStoreAddress());
var appleUrl = 'maps:q=$query';
var googleUrl = 'https://www.google.com/maps/search/?api=1&query=$query';
_launch(appleUrl);
_launch(googleUrl);
Future<void> _launch(String url) async {
await canLaunch(url)
? await launch(url)
: _showSnackBar('could_not_launch_this_app'.tr());
}
Run Code Online (Sandbox Code Playgroud)
一切都很好,直到我收到此警告:
info: 'canLaunch' is deprecated and shouldn't be used. Use canLaunchUrl instead.
Run Code Online (Sandbox Code Playgroud) 我使用 url_launcher 包将邮件集成到 flutter 中的方案中。主题和正文作为查询参数给出。
final Uri _emailLaunchUri = Uri(
scheme: 'mailto',
path: 'mail@qapp.how',
queryParameters: {
'body':
'this is sample text'
}
);
Run Code Online (Sandbox Code Playgroud)
这将给出邮件中的文本this+is+sample+text
。
我正在使用 url_launcher 页面中的文档:https://pub.dev/packages/url_launcher#android
AndroidManifest.xml:
<queries>
<!-- other intents ... -->
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
Run Code Online (Sandbox Code Playgroud)
代码:
final Uri emailLaunchUri = Uri(
scheme: 'mailto',
path: 'smith@example.com',
);
launch(emailLaunchUri.toString());
Run Code Online (Sandbox Code Playgroud)
并得到下一个错误:
E/flutter (11956): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(ACTIVITY_NOT_FOUND, No Activity found to handle intent { mailto:smith@example.com }, null, null)
E/flutter (11956): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (11956): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter (11956): <asynchronous suspension>
E/flutter (11956): #2 launch (package:url_launcher/url_launcher.dart:99:23)
E/flutter (11956): <asynchronous suspension>
E/flutter (11956): #3 MoreTab.build.<anonymous closure> (package:app/screens/fixtures_screen/more_tab/more_tab.dart:34:13)
E/flutter …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Flutter 的url_launcher插件来打开网页。
当我单击按钮 url_launcher 时,成功打开网页。但是,如果我随后通过向左滑动或使用软后退按钮导航回来,应用程序就会崩溃。日志说
java.lang.RuntimeException:无法销毁活动{uk.co.pottertour.map_edinburgh_guide_airbnb/io.flutter.plugins.urllauncher.WebViewActivity}:java.lang.IllegalArgumentException:接收器未注册:io.flutter.plugins.urllauncher.WebViewActivity$1 @8152196
它说 WebViewActivity 所以大概 Url_Launcher 没有打开外部浏览器,而是打开应用程序内的 Webview。
这非常关键,这个应用程序基本上是令人兴奋的事情的中心。
我怀疑是我的didChangeAppLifecycleState
函数导致了错误,因为它是在恢复时发生的,但不是,这是在 Flutter 运行构建并重建屏幕时发生的。
我尝试注释掉我的构建过程中包含 url_launcher 链接的部分,相信重建触发了它,但这没有帮助。也许有一些后台异步进程会在应用程序绘制到屏幕之前引发此错误。与 url_launcher 相关。
我在我的 flutter 项目中使用了url_launcher: ^6.1.0 。我开始为我的小部件编写测试,但是使用url_launcher方法启动 URL 的小部件部分在运行测试时无法正常工作。
我在小部件中使用的方法之一如下所示:
Future<void> _onTapLink(String? href) async {
if (href == null) return;
// canLaunchUrl method never return anything when we are calling this function inside flutter test
if (await canLaunchUrl(Uri.parse(href))) {
await launchUrl(Uri.parse(href));
} else {
print('cannot launch url: $href');
}
}
Run Code Online (Sandbox Code Playgroud)
当我们在 flutter 测试中调用此函数时,canLaunchUrl方法永远不会返回任何内容。
我正在寻找一种方法来模拟url_launcher包以使用内部颤动测试。
我已经更新了我的 flutter 应用程序包,包括从到 的url_launcher
包。6.0.20
6.1.2
更新后,许多 Android 用户 (API 30/31/32) 报告称,由于出现错误,他们无法使用 Google 地图应用启动导航至指定点(纬度和经度):
\nWebpage not available. \n\nWebpage not available\nThe webpage at intent://maps.app.goo.gl/?\nlink=https://www.google.com/maps/dir//45.8597077,.........\ncould not be loaded because:\nnet: ERR_UNKNOWN_URL_SCHEME\n
Run Code Online (Sandbox Code Playgroud)\n这是我的工作代码6.0.20
Webpage not available. \n\nWebpage not available\nThe webpage at intent://maps.app.goo.gl/?\nlink=https://www.google.com/maps/dir//45.8597077,.........\ncould not be loaded because:\nnet: ERR_UNKNOWN_URL_SCHEME\n
Run Code Online (Sandbox Code Playgroud)\n这是不工作的6.1.2
final String gMapsUrl = \'https://www.google.com/maps/dir/api=1&destination=$latitude,$longitude&travelmode=driving\';\n\nif (Platform.isAndroid && await canLaunch(gMapsUrl)) {\n await launch(gMapsUrl);\n}\n
Run Code Online (Sandbox Code Playgroud)\n现在启动 Google 地图 url 以便启动应用内或网络浏览器导航而不强制用户使用应用内或网络导航的正确方法是什么?
\n[\xe2\x9c\x93] Flutter (Channel stable, 2.10.3, on macOS …
Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个小链接,上面写着“向我们发送电子邮件”。当您单击它时,我希望打开默认电子邮件应用程序,并向我们的电子邮件地址发送一封电子邮件。launch()
我曾经用包中的方法让它完全做到这一点,url_launcher
如下所示:
import 'package:url_launcher/url_launcher.dart' as url;
Future<bool?> pressedSendUsEmail() async {
bool? success;
try {
print('Pressed Send us an e-mail...');
success = await url.launch('mailto:our.email@gmail.com'); // Works like a charm...
print('success is $success');
} catch (e) {
print('Caught an error in Send us an e-mail!');
print('e is: ${e.toString()}');
}
return success;
}
Run Code Online (Sandbox Code Playgroud)
但现在,我收到一条警告,说launch()
已弃用!我应该用它launchUrl()
来代替。但launchUrl()
不接受 String 参数,它接受 Uri 参数...并且我不知道如何正确编写此 Uri,以便它执行我想要的操作!我试过:
success = await url.launchUrl(Uri(path: 'mailto:our.email@gmail.com'));
Run Code Online (Sandbox Code Playgroud)
但这会引发错误,因为它无法解释“:”字符。我试过了:
success = await url.launchUrl(
Uri.https('mailto:our.email@gmail.com', ''),
);
Run Code Online (Sandbox Code Playgroud)
这会启动链接,但在浏览器中......并且不会启动发送到预先打印的地址的电子邮件。我尝试添加:
success …
Run Code Online (Sandbox Code Playgroud) 我正在使用url_launcher (6.1.5),我想在默认浏览器而不是应用程序内的 webView 中打开网址。
最新版本似乎不支持它,因为launch函数已被弃用,并且launchUrl不支持该forceWebView=false
标志。
如何使用默认浏览器运行我的网址url_launcher
?
Flutter url_launcher dart 包中的“launch”方法已弃用,需要替换为 launchURL。但launchURL方法没有forceSafariVC参数。
考虑到forceSafariVC参数,迁移到这个新方法会是什么样子?
我的应用程序有一些图标,问题是我将图标设置为一个图标的扩展名/父项,因此当我设置一个图标以转到某个网址时,所有其他图标也会转到该网址。但这不是我想要的,我希望每个图标都转到单独的网址。扩展图标的代码是:`
Row(
children: [
Expanded(
child: TaskCard(
label: "Teachers",
)),
Expanded(
child: TaskCard(
imageUrl: "assets/school-bag.png",
label: "EduPage",
pageUrl: "https://willowcosta.edupage.org",
)),
Run Code Online (Sandbox Code Playgroud)
`
SizedBox(
height: 20.0,
),
Text(
"Sections",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
fontFamily: "SpaceGrotesk",
color: Colors.black),
),
//Here we set the "Shortcuts"
//If you click Teachers it will take you the page where you can see the Teachers -
//names a nd availabity alongs side the subject they teach
//If you click EduPage it takes you to …
Run Code Online (Sandbox Code Playgroud) flutter ×11
url-launcher ×11
dart ×5
mailto ×2
deprecated ×1
email-client ×1
mocking ×1
mockito ×1
plugins ×1
testing ×1
url ×1