如何使用Flutter在iPhone上打开默认电子邮件应用程序?

Pet*_*all 10 email ios dart flutter

我想制作一个Flutter应用程序,其中一个要求是在Android或iPhone设备上打开本机电子邮件客户端.我不想创建新的电子邮件,只需打开电子邮件应用程序.如果可能的话,我希望能够使用平台通用代码打开电子邮件客户端,如果不是,我想知道iOS端需要什么.我不是在寻找发送电子邮件意图,因为我知道Flutter中有一个插件.作为Android开发人员,我相信我知道如何从Flutter调用Intent Intent的Intent,如果我必须这样做,但我对iOS不熟悉.

Gün*_*uer 16

url_launcher插件不说

mailto:<email address>?subject=<subject>&body=<body>
Run Code Online (Sandbox Code Playgroud)

在默认电子邮件应用中创建电子邮件

另请参阅如何从我的Flutter代码中打开Web浏览器(URL)?

  • 我不想创建新的电子邮件,我只想打开默认的电子邮件应用程序。 (3认同)

Buf*_*ffK 14

你需要两个插件:android_intenturl_launcher

if (Platform.isAndroid) {
  AndroidIntent intent = AndroidIntent(
    action: 'android.intent.action.MAIN',
    category: 'android.intent.category.APP_EMAIL',
  );
  intent.launch().catchError((e) {
    ;
  });
} else if (Platform.isIOS) {
  launch("message://").catchError((e){
    ;
  });
}
Run Code Online (Sandbox Code Playgroud)

  • `android_intent` 已替换为 `android_intent_plus` (5认同)
  • 在 Android 上,这将在您的应用程序中打开电子邮件应用程序。要在新窗口中打开它,请添加:`flags: [Flag.FLAG_ACTIVITY_NEW_TASK]` (3认同)

Bha*_*pal 13

使用 url_launcher 插件url_launcher

Future<void> _launched;

Future<void> _openUrl(String url) async {
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
}
Run Code Online (Sandbox Code Playgroud)

然后是电话

setState(() {
  _launched = _openUrl('tel:${+917600896744}');
});
Run Code Online (Sandbox Code Playgroud)

用于电子邮件

setState(() {
  _launched = _openUrl('mailto:${sejpalbhargav67@gmail.com}'');
});
Run Code Online (Sandbox Code Playgroud)

2021 年 7 月更新

在清单文件中添加以下行

<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>
Run Code Online (Sandbox Code Playgroud)

  • 这将发送一封电子邮件,而不是操作人员想要的。 (7认同)