2

I am trying to launch the gmail app when a user taps on a button in my application. I am using the URL launcher package. Right now, I am testing on android and when I launch URLs for youtube or spotify, the app launches. However, when I try to launch gmail through a gmail url, it is not working.

Here is the URL that I am using: "https://mail.google.com/mail/u/0/#search/thisisasearch". Instead of launching to the app, it launches to the browser. Can anyone help me figure this one out?

Also if anyone knows how to implement this on iOS, that would be greatly appreciated!

Dzuko
  • 65
  • 4
  • 8

2 Answers2

4

To open default mail of the application you can use below code

  _sendMail() async {
    // Android and iOS
    const uri =
        'mailto:test@example.org?subject=Greetings&body=Hello%20World';
    if (await canLaunch(uri)) {
      await launch(uri);
    } else {
      throw 'Could not launch $uri';
    }
  }

you can send URI as below for different operations as well apart from mail

  1. For Call - 'tel:+phonenumber'
  2. For SMS - 'sms:+phonenumber'
1

you can use flutter_appavailability library

  1. Import below packages:

     import 'dart:io'; 
     import 'package:flutter_appavailability/flutter_appavailability.dart';
    
  2. Use below method:

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

look : Reference

  • 1
    how would I open the specific to a specific inbox and a search keyword with this method? – Dzuko Aug 06 '20 at 19:24