WP7 and using Launchers

I was creating a Windows Phone 7 application where I wanted to add a “Review” and “Feedback” button so that the users can easily give ratings and feedback to me through the application. And I found a very good How-to guide at msdn. So this post is basically a copy past from that page.

The Launcher APIs belong to the Microsoft.Phone.Tasks namespace. You need to add a using directive for this namespace to the PhoneApplicationPage class file. All of the Launcher APIs function in a similar manner. First, you create an instance of the Launcher class you wish to use. Next, you set properties of the Launcher object that will determine the behavior of the task application when it is invoked. For example, you can specify a phone number that will be displayed when the Phone application launches. Finally, you call the Launcher’s Show method to launch the task application.

It is important to note that when you use a Launcher, a separate application is launched to complete the task. For example, the EmailComposeTask invokes the Messaging application. When the separate application is launched, your application is deactivated and is no longer running. After completing the task, the user can return to your application, at which point it is reactivated. So make sure you understand handling activation and deactivation of you application.

EmailComposeTask
EmailComposeTask launches the Email application which displays a new email message. You can optionally specify recipients, a message subject, and a message body that are prepopulated in the new message. The message is not sent until it is initiated by the user.

EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.To = "user@example.com";
emailComposeTask.Body = "Email message body";
emailComposeTask.Cc = "user2@example.com";
emailComposeTask.Subject = "Email subject";
emailComposeTask.Show();

MarketplaceDetailTask
MarketplaceDetailTask launches the Windows Phone Marketplace client application which then shows the details page for a product specified by the unique identifier you provide. If you do not provide an identifier, the details page for the calling application is shown. The only allowed value for the ContentType property is Applications.

// Show an application, using the default ContentType.
MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();
marketplaceDetailTask.ContentIdentifier = "<ID>";
marketplaceDetailTask.ContentType = MarketplaceContentType.Applications;
marketplaceDetailTask.Show();

MarketplaceHubTask
MarketplaceHubTask launches the Windows Phone Marketplace client application. Set the ContentType property to a value from the MarketplaceContentType enumeration to launch the hub to a particular type of content.

MarketplaceHubTask marketplaceHubTask = new MarketplaceHubTask();
marketplaceHubTask.ContentType = MarketplaceContentType.Music;
marketplaceHubTask.Show();

MarketplaceReviewTask
MarketplaceReviewTask launches the Windows Phone Marketplace client application which then displays the review page for your application.

MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
marketplaceReviewTask.Show();

MarketplaceSearchTask
MarketplaceSearchTask launches the Windows Phone Marketplace client application which then shows the search results based on search terms you provide. You must provide a value for the ContentType property to specify what type of content you are searching for unless you are searching for an application, which is the default content type.

To search for an application, use the following code:

//Search for an application, using the default ContentType.
MarketplaceSearchTask marketplaceSearchTask = new MarketplaceSearchTask();
marketplaceSearchTask.SearchTerms = "accelerometer xna";
marketplaceSearchTask.Show();

To search for a music item, use the following code:

//Search for a music item.
MarketplaceSearchTask marketplaceSearchTask = new MarketplaceSearchTask();
marketplaceSearchTask.ContentType = MarketplaceContentType.Music;
marketplaceSearchTask.SearchTerms = "song title";
marketplaceSearchTask.Show();

MediaPlayerLauncher
MediaPlayerLauncher launches the Media Player application and plays the media file you specify. Media files are stored in isolated storage when saved to disk by the application and are stored in the application’s installation directory if they are bundled into the applications .xap file. You must specify one of these locations using the MediaLocationType enumeration. You can optionally specify that one or more controls should be shown by the Media Player using bitwise OR combinations of the MediaPlaybackControls values.

MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher();
mediaPlayerLauncher.Media = new Uri("MyVideo.wmv", UriKind.Relative);
mediaPlayerLauncher.Location = MediaLocationType.Data;
mediaPlayerLauncher.Controls = MediaPlaybackControls.Pause | MediaPlaybackControls.Stop;
mediaPlayerLauncher.Show();

PhoneCallTask
PhoneCallTask launches the Phone application and displays the specified phone number and display name. The phone call is not placed until it is initiated by the user.

PhoneCallTask phoneCallTask = new PhoneCallTask();
phoneCallTask.PhoneNumber = "55555555555";
phoneCallTask.DisplayName = "Gage";
phoneCallTask.Show();

SearchTask
SearchTask launches the Search application and performs search query you provide.

SearchTask searchTask = new SearchTask();
searchTask.SearchQuery = "XBox game trailers";
searchTask.Show();

SmsComposeTask
SmsComposeTask launches the Messaging application which displays a new SMS message. You can optionally specify recipients and a message body that are prepopulated in the new message. The message is not sent until it is initiated by the user.

SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = "5555555555";
smsComposeTask.Body = "Check out this new app.";

WebBrowserTask
WebBrowserTask launches the Web browser and displays the URL you provide.

WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.URL = "http://msdn.microsoft.com"; 
webBrowserTask.Show();

That’s it, so extremly nicely done by Microsoft, very easy to use!
Article at Msdn

There is also a good post about Choosers at Msdn, you probably want to check that out also!
How to use Choosers for Windows Phone

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: