Android: ActivityNotFoundException when no browser is installed/enabled on device
See original GitHub issueWhich Version of MSAL are you using ? MSAL 3.0.4-preview
Platform Xamarin.Android
Actual behavior
When there is no (browser) activity that can handle the auth flow, the app crashes - see stack trace below.
It appears like there was already some work done regarding this issue: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues?q=is%3Aissue+ActivityNotFoundException+is%3Aclosed
The problem is that it is not possible to catch the MsalClientException thrown here by using try-catch around await clientApplication.AcquireTokenInteractive(Scopes)
Please note: In order to reproduce the issue, not only disabled Chrome, but also uninstall any other browser (like Edge).
Android.Content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://login.microsoftonline.com/… pkg=com.dashlane (has extras) }
JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args)
JniPeerMembers+JniInstanceMethods.InvokeAbstractVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
CustomTabsIntent.LaunchUrl (Android.Content.Context context, Android.Net.Uri url)
AuthenticationActivity.OnResume ()
Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.61(intptr,intptr)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://login.microsoftonline.com/... pkg=com.dashlane (has extras) }
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
android.app.Activity.startActivityForResult(Activity.java:3951)
android.app.Activity.startActivityForResult(Activity.java:3912)
android.app.Activity.startActivity(Activity.java:4235)
android.support.v4.content.ContextCompat.startActivity(ContextCompat.java:248)
android.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:263)
microsoft.identity.client.AuthenticationActivity.n_onResume(Native Method)
microsoft.identity.client.AuthenticationActivity.onResume(AuthenticationActivity.java:48)
android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258)
android.app.Activity.performResume(Activity.java:6347)
android.app.ActivityThread.performResumeActivity(ActivityThread.java:3110)
android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3152)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2499)
android.app.ActivityThread.access$900(ActivityThread.java:157)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:148)
android.app.ActivityThread.main(ActivityThread.java:5525)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (4 by maintainers)
Top GitHub Comments
It doesn’t matter to me if the
ActivityNotFoundException
is wrapped into aMsalClientException
or not (currently it is being wrapped) - I just want to be able to catch it in my code (when callingAcquireTokenInteractive
). Currently the app just crashes and the only way to handle the exception is to register an event handler for unhandled exceptions:With this workaround, the app still crashes, but I can inform the user via toast and disable the sync logic, that would otherwise run every time when starting the app.
Thanks for your thoughts about the future of MSAL for Xamarin. I don’t know the current state of MSAL.Android but I would assume that similar logic would need to be implemented for developers to catch
ActivityNotFoundException
s in their codeYes, I would expect to be able to catch the exception so the app doesn’t crash - in other words, AcquireTokenInteractive() should throw the exception