How do you open the default email app on an iPhone with Flutter?
Solution 1
The url_launcher plugin does that
mailto:<email address>?subject=<subject>&body=<body>
Create email to in the default email app
See also How do I open a web browser (URL) from my Flutter code?
Solution 2
You need two plugins: android_intent
and 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){
;
});
}
Solution 3
use url_launcher plugin url_launcher
Future<void> _launched;
Future<void> _openUrl(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Then for Phone
setState(() {
_launched = _openUrl('tel:${+917600896744}');
});
for email
setState(() {
_launched = _openUrl('mailto:${[email protected]}'');
});
Update July 2021
Add Following Lines in Manifest File
<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>
Related videos on Youtube
Peter Birdsall
Peter Birdsall [email protected] Reliable, creative, adaptive and loyal, possessing technical, managerial and leadership expertise with experience in technology and business systems. Accomplishments include the creation of an Award winning Decision Support implementation and relocation of our Data Center to a managed co-location. Fulfilled business needs by transitioning to various roles and positions, including management and administration of all back office systems across various hardware platforms. Android Full Stack SDK Developer Development Soft Skills: • SDLC, BI • Database Design • AgileWrap • Design system model • Integration • Self / Outsourcing Android Applications - Google Play (exception *): • Otto Carpool • eRideShare Carpool • DP Image Calculator • AceYourExam • WiFi AirWaves • NDA – MyKickStarter • BCM Entry • BCM Website • BCM Regulations * Mobile API Experience: • Google In-App Billing • Google Admob • Material Design • Facebook SDK • RxJava • Retrofit • Google Volley / GSON • Google Analytics • Deep Linking • Cloud Storage • Espresso • Falcon+ • Accessibility Service • Video Streaming • Permissions 6.0 • Map V2 / NFC • EventBus • Dagger2 Professional Experience: Developer – Mobile Ride Sharing, New York, New York 12/14 to 1/17 Published Android proprietary application – Worked with CEO to create 2 Android applications, one for college students and one for the general public. App includes maps with custom markers and window info, geocoding, forward and reverse, custom sms, Material Design implemented in a Model View Controller framework. Sole full stack Android Developer, acclimate the CEO to Android paradigm vs iPhone. Minimal Viable Product (MVP) published on Google Play, ‘Otto Carpooling’, 60+ screens. MVP: https://play.google.com/store/apps/details?id=com.erideshare.erideshare Developer – Highline Residential, Real Estate Brokerage, New York, New York 3/14 to 8/14 Published Android proprietary application - Performed major role in on-site JAD design sessions with CTO, Project Manager and Designer, providing key Android platform guidance in areas of form factor, device support, UI / UX design, backend, database design, best practices for new proprietary Real Estate application. Sole full stack Android Developer, implemented Google In-App Billing, AdMob, Google Analytics, Widgets, Custom Views, Fonts, Content Provider, Volley, 2D / 3D Animation, RESTful, SDLC. MVP: https://play.google.com/store/apps/details?id=com.hlresidential.aceyourexam Webmaster / Android Developer / IT Support IT Consultant – Bergen Chess Mates, Ridgewood, New Jersey 1/09 to present Android applications: BCMWinTD, BCMWebsite, BCM Regulation Assistant and BCM Notation
Updated on March 22, 2022Comments
-
Peter Birdsall about 2 years
I want to make a Flutter app and one of the requirements is to open the native email client on the Android or iPhone device. I do NOT wish to create a new email, just open the email app. I would like to be able to open the email client with platform generic code if possible, if not I would like to know what would be required on the iOS side. I am not looking for the Send Email Intent, as I know there is a plugin in Flutter for that. Being a Android Developer I believe I know how to call an Intent from Flutter for that Implicit Intent, if I have to go that way, but I don't have the familiarity with iOS.
-
Peter Birdsall almost 6 yearsI don't want to create a new email, I just want to open the default email app.
-
Günter Zöchbauer almost 6 yearsSorry, don't know about that
-
Alejandro Iván almost 6 yearsTry
message:
instead ofmailto: ...
-
Günter Zöchbauer over 5 yearsYou probably need to use
Uri.encodeFull('It is not ok')
orUri.encodeComponent('It isnot ok')
and pass the resulting value instead. -
jbx over 3 yearsThe op clearly said he doesn't want to send an email.
-
jbx over 3 yearsThis will send an email, not what the op wants.
-
zkon over 3 yearsThe library allows you to open the email app without sending the email.
-
Volodymyr Bobyr about 3 years@AlejandroIván is that just for iOS?
-
Gabriel Aguirre almost 3 yearsOn Android, this will open the email app inside your app. To open it in a new window add:
flags: [Flag.FLAG_ACTIVITY_NEW_TASK]
-
scienticious almost 3 yearsAppAvailability is an outdated plugin, if you use this it will generate when you releasing the build . So please avoid using this plugin
-
Abdullah Khan almost 3 yearslaunch("message://") is not working in Simulator
-
JJuice over 2 years
android_intent
has been replaced byandroid_intent_plus
-
Karolina Hagegård almost 2 years
launch
is now deprecated. Now, you should uselaunchUrl
and it doesn't take a String, it takes a Uri(), and I'm struggling with how to write that Uri correctly!... I've made it open in the browser by usingUri.https()
, but not in the e-mail app... There is theUri(path: 'String_path')
but that String can't contain a colon, so I can't write "mailto:".... Help? -
Karolina Hagegård almost 2 years@zkon , I'd recommend you edit your answer to include exactly how to open the email app without sending the email! Otherwise, your answer will get downvoted, because ppl believe (from reading the package documentation) that the package can only send emails. Reading the documentation also takes a lot more time than if you would just write the relevant code here! So that would be very helpful, since you apparently know it.