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

  • As everyone scrambles to protect customers and consumers from the Heartbleed virus, there will be a variety of mitigating solutions offered up to address this pesky bug. There are a variety of points within the data path where solutions could be put into place to mitigate this (and similar) vulnerabilities and customers must choose the most strategic point in the network at which to deploy their selected mitigation. Read this white paper to learn the ins and outs of mitigating the risk of Heartbleed and the …

  • IT decision support impacts all aspects of technology management, from governance and strategy to budgets and resource planning. IT decision support effectiveness often falls prey to data-driven challenges that make it difficult to understand the data in context. These challenges: overwhelming data volumes, heterogeneous data types, and growing data complexity. This Forrester Consulting Paper reports the three key findings from their study conducted, on behalf of BDNA, to test the hypothesis that data …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds