你好,我试着启动电子邮件页面与recipent。我试过Flutter电子邮件发送者谁与Android工作,但不是在iOS为我。所以我尝试了网址启动器做同样的事情,但不工作也与iOS。我使用iOS模拟器,问题可以是这个?
我使用这个url启动器的例子
mailto:xxxxx@xxxxx.com?subject=News&body=New%20plugin
我有此错误
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: Could not launch mailto:xxxx@xxxx.com?subject=News&body=New%20plugin
#0 _menuscreenState._launchURL (package:xxxx/bottom.dart:8285:7)
<asynchronous suspension>
#1 _menuscreenState.build.<anonymous closure>.<anonymous closure> (package:xxxx/bottom.dart:8705:13)
下面是url启动器的完整示例
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String email="contact@ouiquit.com";
_launchEmail() async {
if (await canLaunch("mailto:$email")) {
await launch("mailto:$email");
} else {
throw 'Could not launch';
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primaryColor: Colors.red),
home: Scaffold(
appBar: AppBar(
title: Text('test mail'),
actions: <Widget>[
IconButton(
onPressed: _launchEmail,
icon: Icon(Icons.send),
)
],
),
),
);
}
}
此处为错误
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method canLaunch on channel plugins.flutter.io/url_launcher)
#0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
<asynchronous suspension>
#1 canLaunch (package:url_launcher/url_launcher.dart:112:25)
<asynchronous suspension>
#2 _MyAppState._launchEmail (package:testmail/main.dart:20:15)
<asynchronous suspension>
#3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
#4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:729:32)
#5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
#7 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
#8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/<…>
9条答案
按热度按时间agyaoht71#
这对我在Android和iOS设备上都适用:
如果您也有
subject
和body
,请添加query
参数。sirbozc52#
以上给出的解决方案将适用于
API < 30
,但对于API >= 30
,需要将以下内容添加到您的AndroidManifest.xml
文件中,以便电子邮件发送工作。source
dwbf0jvd3#
这是我使用url_launcher发送邮件时使用的函数:
44u64gxh4#
适用于iOS
iOS模拟器上没有安装电子邮件应用程序,您只能在真实的设备上测试。
jk9hmnmh5#
对于所有仍然想知道为什么它不像我那样工作的人。记住模拟器不能处理mailto,因为邮件应用程序不可用。如果你在调用launch之前使用canLaunch,你会得到更多的信息。
rwqw0loc6#
尝试mailto插件
https://pub.dev/packages/mailto#-readme-tab-
它在设备上的Android和iOS都能工作,工作得很好。
uxhixvfz7#
请试试这个,我用过这个,它对我来说很好用。
axkjgtzd8#
对于iOS,我有这样添加
**
**
72qzrwbm9#
我在我的清单中添加了这一行,我能够开始一个呼叫,打开Map等。
more info