Closed ShadowOfPhantom closed 1 year ago
UPDATE
One of the users fixed it by resetting the default browser. He had Mi browser there. Still relevant, how to get around this more gracefully in order to fix it for everyone?
UPDATE 2
A few hours of research and I found that app receives values from Mi browser but then crashes any way. I attached screenshot from debug. I also noticed that there is no flags. If default browser is Chrome or another regular one, there are 2 flags ClearTop and NewTask. I'll try to continue my research, any help is highlt appreciated. As far as I know there are tons of simillar issues on the Internet so we have a chance to finally solve it :)
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
@ShadowOfPhantom Do you find workaround? I had this issue too!
@ShadowOfPhantom Do you find workaround? I had this issue too!
Nah, but I did something custom. I had to release fixed version of app asap so my implementation is not elegant but it works. Well, I made this:
[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable, Intent.ActionView },
DataScheme = CALLBACK_SCHEME)]
public class AuthActivity : Activity
{
const string CALLBACK_SCHEME = "xochatbot";
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
if (this.Intent != null && !string.IsNullOrWhiteSpace(this.Intent.DataString))
Preferences.Set("signinstring", this.Intent.DataString);
StartActivity(MainActivity.MainAct.Intent);
Finish();
}
}
Then you can pull "signinstring" from preferences on your main activity. You probably can make it better if you know how activity works, but I prefer simplicity here: MAUI can throw exceptions where you don't even expect them.
We have the same issue with MI web browser when using a new .NET 7 MAUI Blazor app. So far we have about 2% of users unable to sign into the app and they all have an Xiaomi device. I guess MI Browser is always the default browser for this phone manufacturer. If the user switches to Chrome as default the problem goes away.
If this link is correct www.oberlo.co.uk then we could be looking at 12% of devices not working if the user has never changed default browser. While this problem perhaps will not occur for all MAUI apps it is a scary number for those of us with public facing apps using WebAuthenticator.
Our current challenge is trying to get these users to switch their default browser from MI. It is a challenge for non technical users and also feels a bit wrong that we are trying to enforce a default web browser. We all know what happens when companies try to enforce a particular browser, it doesn't normally end well! 😊
Whenever we call WebAuthenticatorResult result = await _webAuthenticator.AuthenticateAsync(authOptions);
we get an unhandled exception. We have had no success with the above workaround as the app just crashes out with.
Microsoft.Maui.Authentication.WebAuthenticatorIntermediateActivity.OnCreate(Bundle ) Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr , IntPtr , IntPtr ) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V , IntPtr , IntPtr , IntPtr )
I can confirm the above that the Intent.Flags are not set to the usual ActivityFlags.ClearTop | ActivityFlags.NewTask
but any attempt to correct them or launch another activity still causes the app to crash out. The call to authenticator is wrapped in try catch but this makes no difference.
I can confirm if the user switches to Chrome, DuckDuckGo or Samsung Internet we have no issues. It would be good to have a definite list of browsers that do not work.
What are other peoples experiences and does anyone know if we can stop the global exception from crashing the app?
Same issue on Opera browser. https://play.google.com/store/apps/details?id=com.opera.browser
@ShadowOfPhantom Do you find workaround? I had this issue too!
Nah, but I did something custom. I had to release fixed version of app asap so my implementation is not elegant but it works. Well, I made this:
[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)] [IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable, Intent.ActionView }, DataScheme = CALLBACK_SCHEME)] public class AuthActivity : Activity { const string CALLBACK_SCHEME = "xochatbot"; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (this.Intent != null && !string.IsNullOrWhiteSpace(this.Intent.DataString)) Preferences.Set("signinstring", this.Intent.DataString); StartActivity(MainActivity.MainAct.Intent); Finish(); } }
Then you can pull "signinstring" from preferences on your main activity. You probably can make it better if you know how activity works, but I prefer simplicity here: MAUI can throw exceptions where you don't even expect them.
Thanks @ShadowOfPhantom for sharing the workaround. I have one 2 questions:
Intent i = new Intent(Android.App.Application.Context, typeof(MainActivity));
StartActivity(i);
Thanks again for sharing the solution to solve this issue.
@ShadowOfPhantom Do you find workaround? I had this issue too!
Nah, but I did something custom. I had to release fixed version of app asap so my implementation is not elegant but it works. Well, I made this:
[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)] [IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable, Intent.ActionView }, DataScheme = CALLBACK_SCHEME)] public class AuthActivity : Activity { const string CALLBACK_SCHEME = "xochatbot"; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (this.Intent != null && !string.IsNullOrWhiteSpace(this.Intent.DataString)) Preferences.Set("signinstring", this.Intent.DataString); StartActivity(MainActivity.MainAct.Intent); Finish(); } }
Then you can pull "signinstring" from preferences on your main activity. You probably can make it better if you know how activity works, but I prefer simplicity here: MAUI can throw exceptions where you don't even expect them.
Thanks @ShadowOfPhantom for sharing the workaround. I have one 2 questions:
- On the StartActivity line, you are sending as parameter the Intent, however, the MainAct or name of main activity is not being returned for me. am I missing something? -> I think I fixed this by using:
Intent i = new Intent(Android.App.Application.Context, typeof(MainActivity)); StartActivity(i);
- Could you share how you are pulling the signingstring on your main activity, please?
Thanks again for sharing the solution to solve this issue.
1) MainAct is my referrence of MainActivity as a static field:
public class MainActivity : MauiAppCompatActivity
{
public static Activity MainAct;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
if (MainAct is null)
MainAct = this;
}
...}
With this reference you can return to your actual activity with ease after sign in flow :)
2) On resume activity I invoke an event to check on my sign in page if sign in string has appeared on preferences:
protected override void OnResume()
{
base.OnResume();
App.NeedExtraHandleLoginState?.Invoke();
}
If string exists I parse it and continue sign in flow.
I'd repeat that this is working solution but I made it urgently to fix app crashes after intial release of my app. So if you have a bit more time to realize how intents and activities work then you probably can make and share with us a better workaround. For now I prefer msft team to fix WebAuthenticator to get it work as its best because I have not enough understanding how it works on Android, and where I can go wrong there. I already see too much crashes (I don't want to make things even worse) on my Google Play Console and have no idea why, where and how I can fix them, seems like it's some MAUI issues that going to be fixed in a future with upcoming releases of MAUI ❤️
@mattleibow Are you going to backport this to .net7?
Description
Recently I released a new app with .NET MAUI (you can see here) and it behaves very different from device to device. With some browsers (for example Mi browser) app crashes when user is redirected back to the app with WebAuthenticator.
Here is the exception:
I was trying to turn off shrinks, aot and everything else, nothing helps.
Steps to Reproduce
Select Mi browser as your default browser and try to sign in with Google
Link to public reproduction project repository
I can't share my project
Version with bug
7.0 (current)
Last version that worked well
-
Affected platforms
Android
Affected platform versions
Android 11 (SDK 30), Android 10 (SDK 29)
Did you find any workaround?
No
Relevant log output
No response