Windows Phone 7 Quick Tutorials: Part 6 – Launchers and Choosers

In this sixth article of the WP7 Silverlight series I will discuss the launcher and chooser APIs that enable WP applications to provide common tasks to the users, such as making phone calls, browsing the web or taking pictures.

WP7 applications run isolated in a sandbox; they do not have access to stores such as the contacts list, nor can they directly invoke applications such as the phone or e-mail. To allow applications to perform such tasks, Windows Phone provides two sets of APIs, called Launchers and Choosers.

Launchers

Launchers are APIs that allow applications to do common tasks such as making a phone call, sending an SMS or browsing the web. When a launcher is called, the application is tombstoned. After the launcher terminates, the application is activated again. Launchers to not return any data to the calling application.

The following launchers are available in the Microsoft.Phone.Tasks namespace from the Microsoft.Phone assembly:

  • EmailComposerTask: launches the Email application and displays a new email message
  • MarketplaceDetailTask: launches the Windows Phone Marketplace client application which then shows the details page for a product specified by the unique identifier you provide.
  • MarketplaceHubTask: launches the Windows Phone Marketplace client application.
  • MarketplaceReviewTask: launches the Windows Phone Marketplace client application which then displays the review page for your application.
  • MarketplaceSearchTask: launches the Windows Phone Marketplace client application which then shows the search results based on search terms you provide.
  • MediaPlayerLauncher: launches the Media Player application and plays the media file you specify.
  • PhoneCallTask: launches the Phone application and displays the specified phone number and display name.
  • SearchTask: launches the Search application and performs search query you provide.
  • SmsComposerTask: launches the Messaging application which displays a new SMS message.
  • WebBrowserTask: launches the Web browser and displays the URL you provide.

Let’s see a couple of examples for using launchers. I’ll create a single page Silverlight application with two buttons: “Make Call” and “Visit my blog”.

The first button will open the Phone application displaying the John Doe name and phone number 1234567890. The code is as simple as this:

private void btnPhone_Click(object sender, RoutedEventArgs e)
{
   PhoneCallTask phoneCallTask = new PhoneCallTask();
   phoneCallTask.PhoneNumber = "1234567890";
   phoneCallTask.DisplayName = "John Doe";
   phoneCallTask.Show();
}

If you run the application you’ll notice the phone call is not made until the user presses the “call” button in the Phone application. When the phone call ends, the launcher terminates and the application is re-activated. The image strip below shows several screen shots of the application and the launcher.

The second button will start the web browser and navigate to my blog, www.mariusbancila.ro/blog. The code, again, is very simple:

private void btnWeb_Click(object sender, RoutedEventArgs e)
{
   WebBrowserTask webBrowserTask = new WebBrowserTask();
   webBrowserTask.URL = "http://www.mariusbancila.ro/blog";
   webBrowserTask.Show();
}

The next image strip shows the application and the web browser after starting the launcher.

You can find examples for all the launchers in MSDN.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read