I have a button and I would like to press it to open the dafult application of the phone emails. I tried to search online but I only find references to the url_launcher package which, from what I understand, allows you to open the email app and automatically write to someone, but I don't want this, I just want to open the email app and leave it on the main screen.
CodePudding user response:
you can do it using the url launcher package, after installing it and following the steps of setting it up on your target devices.
use this method:
Future<void> sendMailto({
String email = "[email protected]",
}) async {
final String emailSubject = "some subject here";
final Uri parsedMailto = Uri.parse(
"mailto:<$email>?subject=$emailSubject");
if (!await launchUrl(
parsedMailto,
mode: LaunchMode.externalApplication,
)) {
throw "error"
}
}
now the user will face a popup containing mail services app options to choose. If the user chooses a default mail app on his device, he will be redirected to it automatically.
CodePudding user response:
You are correct that url_launcher
can only be used to create messages. But the plugin android_intent_plus
can help you only open the email app
import 'dart:io' show Platform;
if (Platform.isAndroid) {
AndroidIntent intent = AndroidIntent(
action: 'android.intent.action.MAIN',
category: 'android.intent.category.APP_EMAIL',
);
intent.launch().catchError((e) {
print("Error opening email app: $e");
});
}
CodePudding user response:
You can use this package for send emails https://pub.dev/packages/mailto