Reputation: 70327
How do I open a website with Mono for Android? I assume that I need to use an Intent, but I don't know which one.
Upvotes: 1
Views: 2806
Reputation: 24470
Another possibility is to create a WebView and load an URL there, this way you can have some more control over how it looks and how it reacts to things such as Javascript.
You could create your own activity somewhat like this:
using System;
using Android.App;
using Android.OS;
using Android.Webkit;
using Android.Views;
namespace WebViewSample
{
[Activity(Label = "MyAwesomeWebActivity", MainLauncher = true, Icon = "@drawable/icon")]
public class MyAwesomeWebActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
WebView webView = new WebView(this);
webView.Settings.JavaScriptEnabled = true;
webView.Settings.SetSupportZoom(true);
webView.Settings.BuiltInZoomControls = true;
webView.Settings.LoadWithOverviewMode = true; //Load 100% zoomed out
webView.ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
webView.ScrollbarFadingEnabled = true;
webView.VerticalScrollBarEnabled = true;
webView.HorizontalScrollBarEnabled = true;
webView.SetWebViewClient(new AwesomeWebClient());
webView.SetWebChromeClient(new AwesomeWebChromeClient(this));
AddContentView(webView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));
webView.LoadUrl("http://stackoverflow.com");
}
private class AwesomeWebClient : WebViewClient { }
private class AwesomeWebChromeClient : WebChromeClient
{
private Activity mParentActivity;
private string mTitle;
public AwesomeWebChromeClient(Activity parentActivity)
{
mParentActivity = parentActivity;
mTitle = parentActivity.Title;
}
public override void OnProgressChanged(WebView view, int newProgress)
{
mParentActivity.Title = string.Format("Loading {0}%", newProgress);
mParentActivity.SetProgress(newProgress * 100);
if (newProgress == 100) mParentActivity.Title = mTitle;
}
}
}
}
You have a ton of possibilities here.
Upvotes: 2
Reputation: 10139
var intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://www.stackoverflow.com"));
StartActivity(intent);
Upvotes: 4