Trying to open the default browser using xamarin android with c#

时间:2016-07-11 21:40:27

标签: c# android xamarin

so in c# I use System.Diagnostics.Process.Start("https:/.....) and that works great. So far, everything I've ported over to Xamarin Android has worked, except this. When this executed in the Android app, nothing...zip...nada.

2 个答案:

答案 0 :(得分:5)

from the Xamarin docs:

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

答案 1 :(得分:0)

您可以使用应用中的网址打开Chrome browser

string urlString = "http://google.com";
Intent intent1 = new Intent(Intent.ActionView, Uri.Parse(urlString));
intent.AddFlags(ActivityFlags.NewTask);
intent.SetPackage("com.android.chrome");
try
{
    context.StartActivity(intent1);
}
catch (ActivityNotFoundException ex)
{
    //Chrome browser not installed
    intent.SetPackage(null);
    context.StartActivity(intent1);
}