Xamarin Android deep link: can't set default app for link with in-app browser

Andreas Lundgren 1 Reputation point
2021-06-17T11:24:30.237+00:00

Hi,

I have some difficulties making deep linking work in my app for Android together with the in-app browser from Xamarin.Essentials. The problem is the app settings, I can't find a way to set the default setting to open correct links with the app automatically. If I use the external browser it works as expected, when I get navigated the disambiguation dialogue shows and I can choose to always open these links with the app. So clearly the main deep link setup works. However, I don't get this dialogue with the in-app browser which makes sense, since I'm already in the app, but I need a way to manipulate the app settings to respond to these links, preferably automatically. After the setting has been set correctly, the in-app browser closes automatically as expected.

My IntentFilters looks like this:

[IntentFilter(new[] { Intent.ActionView },
DataScheme = "https",
DataHost = "example.com",
DataPathPrefix = "/path/1",
AutoVerify = true,
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable })]
[IntentFilter(new[] { Intent.ActionView },
DataScheme = "https",
DataHost = "example.com",
DataPathPrefix = "/path/2",
AutoVerify = true,
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable })]

Any ideas?
Thanks!

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,336 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,951 Reputation points
    2021-06-18T09:47:43.997+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    We cannot set with in-app browser as the default app for link. Because in App-Linking, Android will delegate to a registered application. The in-app browser cannot work as an independent application. You could check the source code of the Xamarin.Essentials.Browser, the SystemPreferred mode just starts an intent to load the url instead of starting an Activity.

    To load the url in in-app browser, try using Browser.OpenAsync method with BrowserLaunchMode.SystemPreferred mode like below.

       Browser.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);  
     
    

    Related doc: https://learn.microsoft.com/en-us/xamarin/essentials/open-browser?tabs=android

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.