Thomas
Thomas

Reputation: 231

Open a webpage without using webview

I'd like to open a webpage using the webbrowser on the device. Right now I use a WebView, but I want to let the user choose between Chrome, Safari or any other webbrowser currently on the device. Is there any way to do this?

Upvotes: 4

Views: 7327

Answers (4)

Thomas
Thomas

Reputation: 231

var url = "http://www.google.com";
Device.OpenUri(new Uri(url));

And this uses the default browser to open the url.

Source: https://forums.xamarin.com/discussion/comment/94202#Comment_94202

API Docs: Xamarin.Forms.Device.OpenUri

Upvotes: 15

nur farazi
nur farazi

Reputation: 1207

simple solution ,

WebView web_view;

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        SetContentView (Resource.Layout.Social);


        web_view = FindViewById<WebView> (Resource.Id.webView);
        web_view.Settings.JavaScriptEnabled = true;
        web_view.SetWebViewClient (new HelloWebViewClient ());
        web_view.Settings.LoadWithOverviewMode = true;
        web_view.Settings.UseWideViewPort = true;
        web_view.LoadUrl ("http://www.facebook.com");


    }

    public class HelloWebViewClient : WebViewClient
    {
        public override bool ShouldOverrideUrlLoading (WebView view, string url)
        {
            view.LoadUrl (url);
            return true;
        }
    }

Upvotes: 0

hericson
hericson

Reputation: 120

I'm using this code:

var uri = Android.Net.Uri.Parse ("http://www.google.com");
var intent = new Intent (Intent.ActionView, uri); 
StartActivity (intent);

And the compact version:

StartActivity (new Intent (Intent.ActionView, Android.Net.Uri.Parse ("http://www.google.com"))); 

Upvotes: 2

Maxime
Maxime

Reputation: 87

I think it's the default web browser who open the webpage that you want.

Try to see this way.

Upvotes: -2

Related Questions