How do I launch the email client directly to inbox view?
Asked Answered
P

4

5

Is this even possible without calling a specific package? I have found countless examples of sending email via intent, but I can find nothing about simply opening the default email client on the device via button press (preferably with a chooser dialog in case the user has multiple clients).

Propolis answered 15/8, 2010 at 20:21 Comment(2)
I'm curious why you want to do this.Grindstone
The client wants their app to have an "email" button which simply launches the default mail client to check company mail.Propolis
I
7

There is no standard Intent action to open the "inbox view" of "the default email client on the device".

Inferior answered 15/8, 2010 at 22:54 Comment(2)
Is there any standard intent action I can use to open the default email client? (Even if it's not the inbox view - just launch the app in the same way touching the icon on the home screen would launch it)Propolis
Ok, thanks for the info. Looks like I'm calling a specific package, then.Propolis
S
19

There is no default/easy way to do this. This code worked for me. It opens a picker with all email apps registered to device and straight to Inbox:

    Intent emailIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:"));
    PackageManager pm = getPackageManager();

    List<ResolveInfo> resInfo = pm.queryIntentActivities(emailIntent, 0);
    if (resInfo.size() > 0) {
        ResolveInfo ri = resInfo.get(0);
        // First create an intent with only the package name of the first registered email app
        // and build a picked based on it
        Intent intentChooser = pm.getLaunchIntentForPackage(ri.activityInfo.packageName);
        Intent openInChooser =
                Intent.createChooser(intentChooser,
                        getString(R.string.user_reg_email_client_chooser_title));

        // Then create a list of LabeledIntent for the rest of the registered email apps 
        List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
        for (int i = 1; i < resInfo.size(); i++) {
            // Extract the label and repackage it in a LabeledIntent
            ri = resInfo.get(i);
            String packageName = ri.activityInfo.packageName;
            Intent intent = pm.getLaunchIntentForPackage(packageName);
            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }

        LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
        // Add the rest of the email apps to the picker selection
        openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
        startActivity(openInChooser);
    }
Subvert answered 28/1, 2015 at 10:46 Comment(5)
Initially this looked like very scary code, but it worked nonetheless! I added an else statement for phones which have no mail client installed.Picasso
This code was the only one solution which I found to help me open email inbox (without to write new email message), and at the same time it gives you chooser dialog, which is awesome , Thanks LarisaDoriandoric
The only bit of code out there that works. You should wrap it into a helper and throw it on GitHub Gists. THNX!Copalite
The best answer by far. Creates a chooser of all emails available, and when clicked, just launches the app.Cull
For newer version of android and kotlin check this answer https://mcmap.net/q/169539/-how-to-open-the-default-mail-inbox-from-android-codeBasin
I
7

There is no standard Intent action to open the "inbox view" of "the default email client on the device".

Inferior answered 15/8, 2010 at 22:54 Comment(2)
Is there any standard intent action I can use to open the default email client? (Even if it's not the inbox view - just launch the app in the same way touching the icon on the home screen would launch it)Propolis
Ok, thanks for the info. Looks like I'm calling a specific package, then.Propolis
I
4

This one works nowadays

   Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.APP_EMAIL");
        startActivity(Intent.createChooser(intent, ""));
Imminence answered 15/8, 2018 at 5:30 Comment(7)
This will only open Gmail, not open a chooser for the email app of your choice.Cull
Okay, which android version? I'm fairly sure that it gave the chooser last year when I tried it, provided that you have more than one app that claims to do that APP_EMAIL.Imminence
Nexus 5X API 28, Pixel 2 API 28Cull
I just tried this code on nexus 5x api 29 emulator after installing the samsung email client and it gives a choice between the two email clients. After uninstalling the samsung email client from the emulator it will just open gmail directly. What other email client did you have installed in the emulator? maybe it doesn't implement the listener for the intent like it should.Imminence
I had Yahoo Mail installed as an app on the emulator. On my own Samsung 7 I also had Outlook, which did not open with this version. Have you tried on earlier api levels ? I recommend you trying this again as it doesn't appear to be working the way you intend.Cull
Thanks, this code works for me. Intent intent= new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_APP_EMAIL); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(Intent.createChooser(intent, ""));Hewet
Maybe I should have added the caveat that if for an action you have selected the "Always use this app" it will not ask which app to use until you install another app that has a handler for the action.Imminence
G
1

you can try this from your activity object:

it will not necessarily take you to the Inbox directly but it will open the email application:

Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.email");
startActivity(intent); 
Gonzales answered 26/4, 2011 at 19:56 Comment(2)
This one just works, if the Android Email client is the default email program (rarely the case). If it's not, startActivity throws an exception.Dulce
even if its the default app it wouldn't work.i remember that some htc phone had the email package named differently, something like "com.htc.android.email". so this wouldn't workGonzales

© 2022 - 2024 — McMap. All rights reserved.