How to Use Launchers in Your Windows Phone 7 Applications

Introduction

In an attempt to provide isolation, Windows Phone 7 platform does not provide applications direct access to some phone features, such as contacts, sending email or taking pictures. This is done to provide sandboxing. However, when applications have a legitimate need to access these features directly, there are some helper APIs that provide this functionality. These APIs invoke distinct built-in applications, which replace the currently running application, to do the task at hand (sending email, taking picture, etc.).

Launchers defined

Launchers are a set of APIs that launch one of the build-in applications by which the user can complete a task for which the Windows Phone 7 platform provides a native application. An example would be sending an email or taking a picture via the built-in camera.

Developers will author their applications such that their application code calls the Launcher APIs with the required information and the Launcher API will do the specified task. For example, you can provide a phone number to a Launcher API and it can initiate a phone call and switch from the currently executing application to the phone application. When the user is finished with the call, the context switches back to the originally executing application.

One thing to note is that Launcher APIs do not have a return value.

Types of Launchers

There are various Launchers available with Windows Phone 7:

  • Email composition
  • For Marketplace detail
  • For Marketplace hub
  • For Marketplace review
  • For Marketplace search
  • For launching Media Player
  • For Phone call
  • For Search
  • For composing SMS
  • For Web browsing

Let's look at how we can use these Launchers in an application

 

Hands-On

Let us start by creating a new Silverlight C# project for Windows Phone. Let's call it LauncherDemo.

Creating a new Silverlight C# project for Windows Phone
Figure 1: Creating a new Silverlight C# project for Windows Phone

Add a button with the text "Launch Media Player."

In the MainPage.xaml.cs, add a reference directive for Microsoft.Phone.Tasks namespace.

On the button click event, add the following code.

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher();
            mediaPlayerLauncher.Media = new Uri("http://media.ch9.ms/ch9/e77b/b21d7957-7a8e-4f0b-8cf5-9e8c011de77b/sltv62_ch9.wmv", UriKind.RelativeOrAbsolute);
            mediaPlayerLauncher.Location = MediaLocationType.Data;
            mediaPlayerLauncher.Controls = MediaPlaybackControls.Pause | MediaPlaybackControls.Stop;
            mediaPlayerLauncher.Show();

        }

You will note that we are passing in a media file from the internet. You can actually see the video at MSDN Channel 9.

Now, when you compile and run this application in the emulator, you will hear the music from the WMV file being played.

You can verify that you are playing a real internet file by playing the video on MSDN Channel 9 and verifying if the introductory music is the same or not.

If you use the Back button while the music is playing, you will return back to the LauncherDemo application.

If you deploy this XAP file to a phone device, you can actually see the video with the audio. With the Windows Phone emulator, you will only hear audio. (That is the limitation of the current version of the emulator).

If you are having trouble with following up, you can download the demo code which accompanies this article.

Summary

In this article, we learned how to use Launchers to access certain phone functionality.B This allows application developers to worry about their application instead of trying to re-invent the wheel and figure out how to write a music player (for example).

About the author

Vipul Patel is a Software Engineer currently working at Microsoft Corporation. He is currently working in the Office Communications Group and has worked in the .NET team earlier in the Base Class libraries and the Debugging and Profiling team. He can be reached at vipul_d_patel@hotmail.com



About the Author

Vipul Vipul Patel

Vipul Patel is a Software Engineer currently working at Microsoft Corporation, working in the Office Communications Group and has worked in the .NET team earlier in the Base Class libraries and the Debugging and Profiling team. He can be reached at vipul_d_patel@hotmail.com

Related Articles

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • "Security" is the number one issue holding business leaders back from the cloud. But does the reality match the perception? Keeping data close to home, on premises, makes business and IT leaders feel inherently more secure. But the truth is, cloud solutions can offer companies real, tangible security advantages. Before you assume that on-site is the only way to keep data safe, it's worth taking a comprehensive approach to evaluating risks. Doing so can lead to big benefits.

  • Mobile is introducing sweeping changes throughout your workplace. As a senior stakeholder driving mobile initiatives in your organization, you may be lost in a sea of technologies and claims from vendors promising rapid delivery of applications to your employees, customers, and partners. To help explain some of the topics you will need to be aware of, and to separate the must-haves from the nice-to-haves, this reference guide can help you with applying a mobile strategy in the context of application …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds