question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android: ActivityNotFoundException when no browser is installed/enabled on device

See original GitHub issue

Which 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:closed
  • Created 4 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tipacommented, Dec 13, 2021

It doesn’t matter to me if the ActivityNotFoundException is wrapped into a MsalClientException or not (currently it is being wrapped) - I just want to be able to catch it in my code (when calling AcquireTokenInteractive). Currently the app just crashes and the only way to handle the exception is to register an event handler for unhandled exceptions:

AndroidEnvironment.UnhandledExceptionRaiser += (s, e) =>
{
    if (e.Exception is MsalClientException me && me.ErrorCode == "android_activity_not_found")
    {
        ShowToast("No web browser found. Plese install or enable a web browser.");
        Settings.SyncMode = SyncMode.Disabled;
    }
};

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 ActivityNotFoundExceptions in their code

1reaction
tipacommented, Jul 1, 2020

Yes, I would expect to be able to catch the exception so the app doesn’t crash - in other words, AcquireTokenInteractive() should throw the exception

Read more comments on GitHub >

github_iconTop Results From Across the Web

No Activity found to handle Intent : android.intent.action.VIEW
This exception can raise when you handle Deep linking or URL for a browser, if there is no default installed. In case of...
Read more >
Fulfill common use cases while having limited package ...
An ActivityNotFoundException occurs because there isn't an app installed on the device that can open the URL. (This is unusual.).
Read more >
Easy Solution to No Activity Found To Handle Intent Error
No activity found to handle intent is an error caused by different reasons such as Google Play is not installed, using a rooted...
Read more >
ActivityNotFoundException Class (Android.Content)
This exception is thrown when a call to Context#startActivity or one of its variants fails because an Activity can not be found to...
Read more >
How to let native applications handle content
The approach is to try to launch an intent and use Intent.FLAG_ACTIVITY_REQUIRE_NON_BROWSER to ask Android to avoid browsers when launching. If ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found