Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Android Outlook application from an external one

I'm currently developing an Android application in order to display home screen widgets. Those ones are related to Microsoft Outlook (Events + Messages) in order to show incoming events and unread new messages in a kind of dynamic tiles.

The Msal graph library helps me a lot to authenticate and retrieve in formations which contains an identifier for each event / message results

But now I want to know if the outlook application is installed on the user device and if there is a way to open Outlook when the user click on the widget. Moreover if the user can open the corresponding clicked event or message with the identifier.

For example the Event widget currently displaying a birthday event. The user click on it. Then it opens Outlook and display directly that birthday event.

Regards

like image 780
Predalpha Avatar asked Aug 23 '19 01:08

Predalpha


People also ask

How can I access Outlook from my Android phone?

Open the Outlook for Android app. Tap Get Started. Enter your company email address, then tap Continue. If prompted, enter your email account password, then tap Sign In.

Why won't my Outlook app open on my Android phone?

Tap on All apps. Tap on Outlook. Tap on Storage & cache. Tap the Clear Data and Clear Cache button to reset the Outlook app on Android 12.


2 Answers

I don't think this is officially documented somewhere. But here's what you can do to find out about it.

You can list all Microsoft applications installed on your device...

        val packages = context.packageManager
            .getInstalledApplications(PackageManager.GET_META_DATA)

        for (info in packages) {
            if(info.packageName.startsWith("com.microsoft", true)){
                Log.d("package name:" + info.packageName)
                Log.d("Launch Activity: " + context.packageManager.getLaunchIntentForPackage(info.packageName))
            }
        }

Take a note of the "launch intent" displayed in the LogCat. You can use that to launch Outlook. Just make sure you don't hard-code those values because Microsoft can change those values at any point, for example the activity class can change. So, instead of doing this...

context.startActivity(
            Intent().apply {
                action = Intent.ACTION_MAIN
                addCategory(Intent.CATEGORY_LAUNCHER)
                setPackage("com.microsoft.office.outlook")
                component = ComponentName("com.microsoft.office.outlook", "com.microsoft.office.outlook.MainActivity")
            }
        )

Do this...

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

Also, remember that getLaunchIntentForPackage and component can return null, so make sure you check for null values properly

like image 71
Leo Avatar answered Oct 10 '22 20:10

Leo


I am relaying a suggestion from a couple of internal folks:

Please try to open the event using one of the following URLs:

  1. ms-outlook://events/open?restid=%s&[email protected] (if you have a regular REST id)

  2. ms-outlook://events/open?immutableid=%s&[email protected] (if you are using an immutable id)

Since immutable IDs are still in preview stage in Microsoft Graph, and customers should not use preview APIs in their production apps, I think option #1 applies to your case.

Please reply here if the URL works, or not, and if you have other related questions. I requested the couple of folks to keep an eye on this thread as well.

like image 4
Angelgolfer-ms Avatar answered Oct 10 '22 21:10

Angelgolfer-ms