xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 506 forks source link

[Bug] Browser.OpenAsync set to launch externally crashes if the link is a youtube link (Android) #1911

Open IeuanWalker opened 3 years ago

IeuanWalker commented 3 years ago

Description

Opening up a youtube link with launch mode set to external causes an exception Xamarin.Essentials.FeatureNotSupportedException: Specified method is not supported.

I'd expect it to either open the YouTube app (like it does when launch mode is set to 'SystemPerfered'), or open the users browser.

iOS works as expected and opens the YouTube app.

Steps to Reproduce

await Browser.OpenAsync("https://www.youtube.com/watch?v=xvFZjo5PgG0", BrowserLaunchMode.External);

Expected Behavior

Either opens the YouTube app or open the users browser

Actual Behavior

FeatureNotSupportedException

Basic Information

OliverMDr commented 2 years ago

You may have to update your Manifest.xml as described in the official documentation here (needed since Android 11): https://docs.microsoft.com/en-us/xamarin/essentials/open-browser?context=xamarin%2Fandroid&tabs=android

IeuanWalker commented 2 years ago

thanks @OliverMDr but we already have that in our app manifest

Magic73 commented 2 years ago

I confirm the issue, but not only with yt links.

e-sly commented 2 years ago

Had the same issue. Check this: https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9

in the app manifest add the following:

<queries>
  <package android:name="com.google.android.youtube" /> <!--it will open the youtube links automatically in app -->
</queries>
LeoJHarris commented 1 year ago

Jumping on board here also, we had a user get the Xamarin.Essentials.FeatureNotSupportedException: Specified method is not supported when trying to call the _browser.OpenAsync() method. The feedback we received was on restarting his phone and trying again it worked fine. The link was a page url and not a video link.

Stacktrace was as follows:

Xamarin Exception Stack:
Xamarin.Essentials.FeatureNotSupportedException: Specified method is not supported.
  at Xamarin.Essentials.Browser.PlatformOpenAsync (System.Uri uri, Xamarin.Essentials.BrowserLaunchOptions options) [0x00164] in <3486249b645141aca15ba2ad775694ec>:0
  at Xamarin.Essentials.Browser.OpenAsync (System.Uri uri, Xamarin.Essentials.BrowserLaunchOptions options) [0x00006] in <3486249b645141aca15ba2ad775694ec>:0
  at Xamarin.Essentials.Browser.OpenAsync (System.String uri, Xamarin.Essentials.BrowserLaunchOptions options) [0x0001e] in <3486249b645141aca15ba2ad775694ec>:0
  at Xamarin.Essentials.Browser.OpenAsync (System.String uri, Xamarin.Essentials.BrowserLaunchMode launchMode) [0x0000d] in <3486249b645141aca15ba2ad775694ec>:0
  at Xamarin.Essentials.Implementation.BrowserImplementation.Xamarin.Essentials.Interfaces.IBrowser.OpenAsync (System.String uri, Xamarin.Essentials.BrowserLaunchMode launchMode) [0x00000] in <1f2aeba57b4c48dba53954e2e1269b66>:0
  at SampleApp.Models.ViewModels.HomeTileViewModel.homeTileOnTappedAsync (SampleApp.Models.ViewModels.HomeTileViewModel homeTileViewModel) [0x0042b] in <5535fe1a2a3a4005a4b551a1bdb49333>:0
  at Xamarin.CommunityToolkit.ObjectModel.Internals.BaseAsyncCommand`2[TExecute,TCanExecute].ExecuteAsync (TExecute parameter) [0x00093] in <9afd4988907a4c9892c2d814a0897a5c>:0
  at Xamarin.CommunityToolkit.Helpers.SafeFireAndForgetExtensions.HandleSafeFireAndForget[TException] (System.Threading.Tasks.Task task, System.Boolean continueOnCapturedContext, System.Action`1[T] onException) [0x0006f] in <9afd4988907a4c9892c2d814a0897a5c>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <e518600c717342cea198fd693233152e>:0
  at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <f09900e46411499aaee1cd003935a463>:0
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <f09900e46411499aaee1cd003935a463>:0
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <f09900e46411499aaee1cd003935a463>:0
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V (_JniMarshal_PP_V callback, System.IntPtr jnienv, System.IntPtr klazz) [0x00005] in <f09900e46411499aaee1cd003935a463>:0
MitchBomcanhao commented 1 year ago

I've found that when a device has more than 1 app that can open a given uri (which here would be the browser and a secondary app), calling Launcher.CanOpenAsync(uri) would return false, but calling Launcher.OpenAsync(uri) would work just fine. Ultimately we had to stop using CanOpenAsync and replace it with a try/catch because it wasn't reliable. It is very likely that the call for Browser.OpenAsync has the exact same failure as Launcher.CanOpenAsync.

see https://github.com/xamarin/Essentials/issues/1947

kwyz commented 1 year ago

Any updates on this issue?

konrad-gora commented 1 year ago

I've found that when a device has more than 1 app that can open a given uri (which here would be the browser and a secondary app), calling Launcher.CanOpenAsync(uri) would return false, but calling Launcher.OpenAsync(uri) would work just fine. Ultimately we had to stop using CanOpenAsync and replace it with a try/catch because it wasn't reliable. It is very likely that the call for Browser.OpenAsync has the exact same failure as Launcher.CanOpenAsync.

see #1947

I have a similar problem like the author. When I disabled opening links in YouTube app, Browser.OpenAsync(uri, BrowserLaunchMode.External) works correctly, but if it is enabled, it fails in the same way.