Search code examples
androidflutteremailpackage

How to open the default email app on Android from Flutter


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.


Solution

  • 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");
      });
    }