9

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

Twisha Kotecha
  • 1,082
  • 1
  • 4
  • 18
Predalpha
  • 139
  • 1
  • 9

4 Answers4

5

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

Leo
  • 14,625
  • 2
  • 37
  • 55
  • Thank you @Leo for that great answer. I was very busy for those last days. Try to implement your solution soon and ill give you a feedback. – Predalpha Aug 25 '19 at 07:10
  • As of Android 11, getInstalledApplications doesn't provide information about all apps – kotoMJ Apr 19 '21 at 19:55
  • @kotoMJ the overload suggested in this answer hasn't been deprecated. The one that was deprecated is the one that doesn't accept any parameters. – Leo Oct 06 '22 at 00:35
5

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&account=test@om.com (if you have a regular REST id)

  2. ms-outlook://events/open?immutableid=%s&account=test@om.com (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.

Angelgolfer-ms
  • 336
  • 2
  • 4
  • Ty @Angelgolfer-ms for your assistance i really apreciate ! Those urls are not working for me. Below my code : String iCalUID = intent.getStringExtra(EXTRA_CALENDAR_iCalUId); String deepLink = "ms-outlook://events/open?restid=%s&account=***@***.**"; deepLink = String.format(deepLink, iCalUID); Intent intentDL = new Intent(Intent.ACTION_VIEW); intentDL.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intentDL.setData(Uri.parse(deepLink)); context.startActivity(intentDL); – Predalpha Sep 19 '19 at 15:54
  • Ive tried with both iCalUID and Id with no success. The best result occurs with a toast message indicating that Outlook cannot open the event. The identifiers im using comes from that request : mClient.me().calendars(calendar.id).calendarView().buildRequest(options) .top(20) .select("subject,bodyPreview,organizer,start,end,isAllDay,webLink,iCalUId") – Predalpha Sep 19 '19 at 16:00
  • @Predalpha, I relayed your results to the internal folks. – Angelgolfer-ms Sep 19 '19 at 23:28
  • @Predalpha were you able to find a solution for this? – Pablo Pantaleon Aug 11 '21 at 18:59
  • No i dont find any solution for this. Only the developers of the microsoft android app could have the answer. I found a workaround using android notification to achieve this even if this is not perfect. – Predalpha Aug 12 '21 at 19:44
0

Well, i managed to open the outlook android application with the help of your code @Leo. As im not developping with Kotlin, ill post the JAVA code below :

Intent outlookLaunchIntent =  context.getPackageManager().getLaunchIntentForPackage("com.microsoft.office.outlook");
                if (outlookLaunchIntent  != null) {
                    context.startActivity(outlookLaunchIntent );
                }

Below code to open event/message in a web browser provided by webLink property of the graph API. (I only test for event and the url provided not working. Ill post a new issue on StackOverFlow for that but you already see the issue over there : https://github.com/microsoftgraph/microsoft-graph-docs/issues/4203

try {
                    Intent webIntent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(calendarWebLink));
                    webIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(webIntent);
                } catch (RuntimeException e) {
                    // The url is invalid, maybe missing http://
                    e.printStackTrace();
                }

However im still stuck on the decicive goal of my widget item click which is to open the relative event/email in the Microsoft Outlook Android application.

Microsoft Outlook Android app contains widgets which can achieve what im looking for. So i wonder if it is possible to list its broadcast receivers.

The best thing i found is an old manifest for that app but it doesnt help me. https://gist.github.com/RyPope/df0e61f477af4b73865cd72bdaa7d8c2

Predalpha
  • 139
  • 1
  • 9
0

Hi may you try to open the event using one of the url:

  • ms-outlook://events/open?restid=%s&account=test@om.com (If the user is having rest id)
  • ms-outlook://events/open?immutableid=%s&account=test@om.com (If the user is having immutable id)
Utkarsh Srivastav
  • 3,105
  • 7
  • 34
  • 53
  • Hello Utkarsh Srivastav, Those 2 urls are trying to open Outlook android app but there might be an error with my event id or something else as Outlook dont take the focus. I can see that if if press the system button to get all opened apps. With [restid] url, Outlook app show me a toast message 'Event couldn't be opened.' Here is the restid = "AQMkADAwATZiZmYAZC05MjQ1LWNlNGMtMDACLTAwCgBGAAADlTUrKZqmfk%2BrNABlMa7wSwcAbUarDFvXZUeDZALCGxo5UgAAAgENAAAAbUarDFvXZUeDZALCGxo5UgACxC11rgAAAA%3D%3D" – Predalpha Sep 23 '19 at 08:45
  • ms-outlook://events/open?restid={id} this works on iOS but not on Android. Does anyone has a workaround for this? – Robert P Oct 23 '19 at 10:01
  • Still not working, I doubt we ll get a workaround on this. – Predalpha Mar 16 '20 at 06:35