Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 597
wirbly Avatar asked Aug 15 '10 20:08

wirbly


People also ask

How do I change my default email program in Chrome?

Google ChromeClick Show Advanced Settings at the bottom of the page. Under "Privacy," click Content Settings. Scroll down to the "Handlers" section, and click the Manage Handlers button. Select your desired, default email client (e.g. Gmail).

How do I set the default Mail client in Windows 10?

In Windows 10, select Start and type Default apps. Select Default apps from the suggestions. Under Email, if Outlook is not listed, select the app that is listed to be presented with a list of email apps installed on your computer, then select Outlook.

How do I set the default Mail client in Windows 11?

To change your default mail app on Windows PC, open the Windows Settings menu by pressing the Win + I. When the Settings tab opens, click on the Apps option and select Default Apps. Now head to the search menu bar and type in the name of the email you'd like to set up as the default email client.

How do I change the default program in mailto?

Open the Settings app (press Windows key + I) and head to Apps > Default apps. Under Set a default for a file type or link type, search for "mailto," which will bring up the Mail protocol. Click it, then select the desired program from the list.


4 Answers

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);
    }
like image 57
Larisa Hogas Avatar answered Nov 11 '22 21:11

Larisa Hogas


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

like image 22
CommonsWare Avatar answered Nov 11 '22 22:11

CommonsWare


This one works nowadays

   Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.APP_EMAIL");
        startActivity(Intent.createChooser(intent, ""));
like image 31
Lassi Kinnunen Avatar answered Nov 11 '22 21:11

Lassi Kinnunen


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); 
like image 21
samer alameer Avatar answered Nov 11 '22 20:11

samer alameer