首页 > 解决方案 > 如何在 url_launcher 中打开 Gmail 应用程序(不创建电子邮件只是打开收件箱)?

问题描述

mailto:<email address>?subject=<subject>&body=<body>

这会创建一封电子邮件。我只想用url_launcher包打开 Gmail 应用程序(收件箱)。可能吗?

标签: flutterdart

解决方案


您需要安装两个插件:android_intent 和 url_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){
    ;
  });
}

推荐阅读