Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

[Bug] Android Crash when open browser with Browser.OpenAsync() #2079

Open
TranTrieuLamQuynh opened this issue Mar 10, 2023 · 2 comments
Open
Labels
bug Something isn't working

Comments

@TranTrieuLamQuynh
Copy link

TranTrieuLamQuynh commented Mar 10, 2023

Description

Steps to Reproduce

I have a problem when open custom tab with Browser.OpenAsync(). But it is very difficult to reproduce. But happens a lot with users. We can only investigate through the AppCenter log.
Has anyone had the same problem as me? Or does anyone have a workaround for this?
Thanks for the help.

Expected Behavior

Browser.OpenAsync() not crash

Actual Behavior

Browser.OpenAsync() crash in CustomTabsIntent.LaunchUrl()

Basic Information

  • Version with issue: 1.7.3
  • Last known good version: no version
  • IDE: VS for Mac/Rider
  • Platform Target Frameworks:
  • Android: API 32

Log crash:

android.os.RemoteException: Remote stack trace:
com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPermission ActivityStackSupervisor.java:2074
com.android.server.am.ActivityStarter.startActivity ActivityStarter.java:1011
com.android.server.am.ActivityStarter.startActivity ActivityStarter.java:648
com.android.server.am.ActivityStarter.startActivityMayWait ActivityStarter.java:1645
com.android.server.am.ActivityStarter.execute ActivityStarter.java:589
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)
Browser.PlatformOpenAsync (System.Uri uri, Xamarin.Essentials.BrowserLaunchOptions options)
Browser.OpenAsync (System.Uri uri, Xamarin.Essentials.BrowserLaunchOptions options)
Browser.OpenAsync (System.String uri, Xamarin.Essentials.BrowserLaunchOptions options)
Browser.OpenAsync (System.String uri, Xamarin.Essentials.BrowserLaunchMode launchMode)
BrowserHelper.OpenAsync (System.String uri)
MessageDetailViewModel.OnExecuteMoreInformationCommandAsync (System.Object obj)
AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state)
SyncContext+<>c__DisplayClass2_0.b__0 ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
android.os.Parcel.createException Parcel.java:1950
android.os.Parcel.readException Parcel.java:1918
android.os.Parcel.readException Parcel.java:1868
android.app.IActivityManager$Stub$Proxy.startActivity IActivityManager.java:3608
android.app.Instrumentation.execStartActivity Instrumentation.java:1674
android.app.Activity.startActivityForResult Activity.java:4694
androidx.activity.ComponentActivity.startActivityForResult ComponentActivity.java:597
android.app.Activity.startActivityForResult Activity.java:4652
androidx.activity.ComponentActivity.startActivityForResult ComponentActivity.java:583
android.app.Activity.startActivity Activity.java:5013
androidx.core.content.ContextCompat$Api16Impl.startActivity ContextCompat.java:828
androidx.core.content.ContextCompat.startActivity ContextCompat.java:276
androidx.browser.customtabs.CustomTabsIntent.launchUrl CustomTabsIntent.java:376
crc64f839d1170f9718f6.CustomerButtonClickListener.n_onClick(Native Method)
crc64f839d1170f9718f6.CustomerButtonClickListener.onClick CustomerButtonClickListener.java:30
android.view.View.performClick View.java:6637
android.view.View.performClickInternal View.java:6614
android.view.View.access$3100 View.java:790
android.view.View$PerformClick.run View.java:26201
android.os.Handler.handleCallback Handler.java:873
android.os.Handler.dispatchMessage Handler.java:99
android.os.Looper.loop Looper.java:224
android.app.ActivityThread.main ActivityThread.java:7030
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:536
Caused by: android.os.RemoteException: Remote stack trace:
com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPermission ActivityStackSupervisor.java:2074
com.android.server.am.ActivityStarter.startActivity ActivityStarter.java:1011
com.android.server.am.ActivityStarter.startActivity ActivityStarter.java:648
com.android.server.am.ActivityStarter.startActivityMayWait ActivityStarter.java:1645
com.android.server.am.ActivityStarter.execute ActivityStarter.java:589

@TranTrieuLamQuynh TranTrieuLamQuynh added the bug Something isn't working label Mar 10, 2023
@MitchBomcanhao
Copy link

MitchBomcanhao commented Apr 21, 2023

random thought:
when using Launcher.OpenAsync(uri) it is recommended to wrap it around with a check for Launcher.CanOpenAsync(uri). perhaps you need a similar check? maybe the uri you are trying to access directly in Browser.OpenAsync(uri) isn't recognised by some of your user's devices and it is blowing up?

I found that some uris would make android devices crash but they'd work fine on iOS and Windows, so there is a degree of variance that you should consider when dealing with this sort of issue.

@MitchBomcanhao
Copy link

MitchBomcanhao commented Aug 25, 2023

as a follow-up to my previous comment, I've found that sometimes Lancher.CanOpenAsync would return false even though the launcher.OpenAsync worked just fine, so I ended up replacing CanOpenAsync with a try/catch. This fault became apparent when the device had more than one application that could open the uri and CanOpenAsync no longer worked as expected.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants