Charles Yeung
Charles Yeung

Reputation: 38795

Windows Phone - Call default web browser

I am trying to develop Windows Phone App, I would like to know that how can I call the default web browser with a specific URL(e.g. http://www.google.com) when I launch the program?

Thanks

Upvotes: 3

Views: 510

Answers (1)

Paul Hazen
Paul Hazen

Reputation: 2473

When you're launching "the program" as you say (Internet Explorer) you use the following code:

WebBrowserTask browser = new WebBrowserTask();
browser.URL = new Uri("http://www.google.com", UriKind.Absolute);
browser.Show();

The WebBrowser task is inside the Microsoft.Phone.Tasks namespace, the documentaion of which is here: Microsoft.Phone.Tasks.WebBrowserTask

You should also know that the "default" browser is always Internet Explorer, because right now there is no way for users to define an alternative browser as their "default".

Edit:

After reading your question more closely, I can tell there is a little bit of ambiguity. If you want to launch the browser immediately when your app launches, you should know the following:

  1. This kind of application will fail Microsoft's marketplace validation (check the Application Certification Requirements for Windows Phone

  2. Even if it didn't fail the certification, it would be a kind of strange application... not one that is of very much use to your users.

If, however you intend to launch the phone's browser when the user clicks a button, then the above code I posted will work just like you want it to, just make sure to include this line at the top of the code file that it's in:

using Microsoft.Phone.Tasks;

Hope that helps!

Upvotes: 4

Related Questions