如何在Flutter中打开默认的电子邮件应用程序收件箱? [英] How to open default email app inbox in flutter?
问题描述
我想使用Flutter打开默认的电子邮件应用程序收件箱"屏幕.我们可以使用url启动器通过mailto:url打开电子邮件撰写屏幕.但这会打开撰写屏幕.我要打开收件箱屏幕.我找不到适合的文档.
I want to open the default e-mail app Inbox screen using flutter. We can use url launcher to open the email compose screen with mailto: url. But that opens the compose screen. What I want is to open the inbox screen. I can't find proper documentation for this.
推荐答案
我找到的答案是使用 flutter_appavailability 一个>库. 对于那些正在寻找答案的人,请参见以下步骤.
I found the answer using flutter_appavailability library. For those who are searching for the answer please see the steps below.
-
添加依赖项| flutter_appavailability:"^ 0.0.21" |
Add dependency | flutter_appavailability: "^0.0.21" | in pubspec.yaml (Please check the latest version in GitHub)
在Xcode Podfile中添加以下行,这是在iOS中构建库所必需的
Add below lines in Xcode Podfile which is required for building the library in iOS
目标亚军" use_frameworks! #由simple_permission要求 ... 结束
target 'Runner' do use_frameworks! # required by simple_permission ... end
post_install做|安装程序| installer.pods_project.targets.each做| target | target.build_configurations.each做| config | config.build_settings ['SWIFT_VERSION'] ='4.0'#simple_permission要求 config.build_settings ['ENABLE_BITCODE'] ='否' 结尾 结尾 结束
post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.0' # required by simple_permission config.build_settings['ENABLE_BITCODE'] = 'NO' end end end
导入以下软件包
导入'dart:io'; 导入'package:flutter_appavailability/flutter_appavailability.dart';
import 'dart:io'; import 'package:flutter_appavailability/flutter_appavailability.dart';
使用以下方法
void openEmailApp(BuildContext context){
try{
AppAvailability.launchApp(Platform.isIOS ? "message://" : "com.google.android.gm").then((_) {
print("App Email launched!");
}).catchError((err) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("App Email not found!")
));
print(err);
});
} catch(e) {
Scaffold.of(context).showSnackBar(SnackBar(content: Text("Email App not found!")));
}
}
这篇关于如何在Flutter中打开默认的电子邮件应用程序收件箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!