0

I'm trying to open an mail application on Android via intent. The purpose is to have a button in the app that will open your mail inbox. However when I use:

val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_APP_EMAIL)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(Intent.createChooser(intent, "Email"))

It always opens gmail, while I also have Outlook installed. The only way I get to choose between the mail apps is when yo use the mailto. But I don't intent to send an email, so it is not desired to use that intent.

Doesn't Outlook support this Intent?

Narendra_Nath
  • 4,578
  • 3
  • 13
  • 31
Arnout
  • 157
  • 1
  • 13

1 Answers1

0

use the following snippet to open to outlook directly from a different app

context.startActivity(
            Intent().apply {
                action = Intent.ACTION_MAIN
                addCategory(Intent.CATEGORY_LAUNCHER)
                component = ComponentName(
                   outlookLaunchIntent?.component?.packageName, 
                   outlookLaunchIntent?.component?.className
                )
                setPackage(outlookLaunchIntent.package)
            }
        )

com.microsoft.office.outlook is the package name for outlook

For sending it to all email clients use a uri like this

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);

Ref:How to open Email program via Intents (but only an Email program)

Narendra_Nath
  • 4,578
  • 3
  • 13
  • 31
  • Thanks for your quick reaction, this can indeed open The Outlook app, however i would like to open a chooser between Gmail and Outlook. Perhaps my question was not formed correctly. Do you also have a sollution for that? – Arnout May 10 '21 at 07:37
  • added the reference as well as the answer most suited to your use case – Narendra_Nath May 10 '21 at 07:43