How to open default browser in Xamarin?

Published

I would like to open a web page in Xamarin for both Android and iOS. The code doesn’t work. Can anyone help me figure out what’s wrong?

For Android, clicking the button goes through the code, but nothing happens afterwards. For iOS, clicking the button does open a Safari page, but it cannot open the page, and displays a message “Safari could not open the page because the server stopped responding.”

The test arg passed is: “http://www.google.com

Thanks.

Code:

    async Task ExecuteLaunchBrowserAsync(string arg)
    {
        if (IsBusy)
            return;

        try
        {
            await CrossShare.Current.OpenBrowser(arg, new BrowserOptions
            {
                ChromeShowTitle = true,
                ChromeToolbarColor = new ShareColor
                {
                    A = 255,
                    R = 100,
                    G = 50,
                    B = 255
                },
                UseSafariReaderMode = true,
                UseSafariWebViewController = true
            });
        }
        catch
        {
        }
    }

Source: Xamarin.ios Questions

Published
Categorised as Uncategorised Tagged , , , ,

Answers

The above “Device.OpenUri();” has now been deprecated so you’ll have to use “Launcher.OpenAsync();” instead like so:

await Launcher.OpenAsync(new Uri("http://example.com"))

Please see docs here:
https://docs.microsoft.com/en-us/dotnet/api/xamarin.essentials.launcher.openasync


Kaci Bechtelar MD

Leave a Reply

Your email address will not be published. Required fields are marked *

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq