所以我知道对于 android version >= 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>
我设法用下面的代码重现了我的机器的错误。不过我得到这个错误:
I/UrlLauncher(10601): mailto:?subject=&body= 的组件名称为空
在下面你可以找到 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) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {return Scaffold(
body: Center(
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0)),
),
),
onPressed: () => launchEmail(
toEmail: "js",
subject: "dm",
message: "jd",
), child: Text("null"),
),
),
);
}
Future launchEmail({
required String toEmail,
required String subject,
required String message,
}) async {
final url =
"mailto:$toEmail?subject=${Uri.encodeFull(subject)}&body=${Uri.encodeFull(message)}";
if (await canLaunch(url)) {
await launch(url);
}
}
}