Open Browser In Xamarin.Essentails Not Working Properly Xamarin.Forms Android

SimonGhost 256 Reputation points
2021-02-04T19:38:35.243+00:00

Hello, how are you I hope you are fine :)
Today I tried using Open Browser In Essentials to Open Chrome Tabs In The Current Page Without Open External Browser,The Document of Microsoft For Xamarin.Essentials (Open Browser) there are requirements for android like
when your project target is Android 11 add Android Manifest with queries ,but my project target not Android 11
So, there is no need to add anything but when i run code
await Browser.OpenAsync("url", BrowserLaunchMode.SystemPreferred);

and i click the button It will show me the browsers in which I can open the link, its just like External Browser but it should show me popup chrome tab with my link Why is this happening with the knowledge I have the latest releases of Xamarin.Essentials Package and Xamarin.Forms Also My Real Device Use Android 10 and My Project Target Version (9.0) Level Pie and already i installed chrome app in my phone :(
i hope someone help me and thanks :)

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

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 77,256 Reputation points Microsoft Vendor
    2021-02-06T01:04:43.937+00:00

    In your device, you have three browsers and you donot set the default browser, So you will get this pop up window that want you to choose one of them to open the url.

    I make a test to install other broswer. I can get the same popup window as you get.
    64774-image.png

    You can set the default browser then make a test, if you can execute code, you cannot get the pop up window, just open the url like your second screenshot.

    64712-image.png

    If you want to know more details about the BrowserLaunchMode.SystemPreferred, we can use source code to verify that is open default browser

    please open the Xamarin.Essentials Browser's source code: https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/Browser/Browser.android.cs

    64802-image.png

    As above source code, we can see the difference between BrowserLaunchMode.SystemPreferred and BrowserLaunchMode.External, BrowserLaunchMode.SystemPreferred use CustomTabsIntent.Builder to open the browser, but BrowserLaunchMode.External to use startActivity to open your url,

    First of all, we can see CustomTabsIntent.Builder, this class come from AndroidX.Browser.CustomTabs;(for android 10.0) or Android.Support.CustomTabs;(before android 10.0), Obviously the class come from native Android ,then we can search the google document about AndroidX.Browser.CustomTabs;, https://developers.google.com/web/android/custom-tabs/implementation-guide#opening_a_custom_tab, in this article, we found Custom Tabs integration is adding the AndroidX Browser Library, In other words,Custom Tabs that used AndroidX Browser Library to achieve it. in the end, open the AndroidX Browser Library, we will found that Display webpages in the user's default browser.

    64776-image.png


2 additional answers

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 77,256 Reputation points Microsoft Vendor
    2021-02-05T02:10:12.027+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    i click the button It will show me the browsers in which I can open the link, its just like External Browser but it should show me popup chrome tab with my link Why is >this happening with the knowledge

    If you set BrowserLaunchMode to SystemPreferred, actually it open an external browser, but stay inside of your application (ChromeCustom Tabs and SFSafariViewController).

    You can open the SystemPreferred’s Comment like following screenshot.

    64371-image.png

    If you want to open the link in your application without external browser, you can use Webview to achieve it.

    64336-image.png

    Best Regards,

    Leon Lu


    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.


  2. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 77,256 Reputation points Microsoft Vendor
    2021-02-06T01:28:19.363+00:00

    And what is difference about BrowserLaunchMode.External and BrowserLaunchMode.SystemPreferred when we used?

    BrowserLaunchMode.External just open external browser, but it cannot custom brower's view, just open the browser, you can see the background task to virtfy it(two application in the background).

    64754-image.png

    BrowserLaunchMode.SystemPreferred could custom brower's view, and just one application in the background.

    custom brower's view https://learn.microsoft.com/en-us/xamarin/essentials/open-browser?context=xamarin%2Fandroid&tabs=android#customization

    64755-image.png

    0 comments No comments

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.