Launchers and Choosers for Windows Phone

Launchers and Choosers are the set of APIs that allow applications indirect access to phone features, such as taking photos with the camera, launching one of the built-in applications, etc.  The difference between Launchers and Choosers is that Launchers just launch a built-in application and no data is returned to the calling application, while for Choosers the chosen data is returned to the application such as a photo stored in the phone.

 

Below is the list of Launchers:

EmailComposeTask launches the Email application which 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.

MarketplaceDetailTask 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. The phone call is not placed until it is initiated by the user.

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

SmsComposeTask launches the Messaging application which displays a new SMS message.

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

 

And below is the list of Choosers:

CameraCaptureTask launches the Camera application for the user to take a photo.

EmailAddressChooserTask launches the Contacts application and allows the user to select a contact's email address.

PhoneNumberChooserTask launches the Contacts application and allows the user to select a contact's phone number.

PhotoChooserTask launches the Photo Picker application for the user to choose a photo.

SaveEmailAddressTask saves the provided email address to the Contacts list.

SavePhoneNumberTask saves the provided phone number to the Contacts list.

 

For an example of how they work, I'll use a modification of my previous slideshow sample to add images to the slideshow from the photos stored on the phone and from the camera capture. 

First, add the namespace:

using Microsoft.Phone.Tasks; 

 

 

Then add the following code:

        PhotoChooserTask photoChooserTask;

        CameraCaptureTask cameraCaptureTask;

        //CameraCaptureTask completed event handler. Set the image source to the captured photo and add it to the list of images.

        void cameraCaptureTask_Completed(object sender, PhotoResult e)

        {

            if (e.TaskResult == TaskResult.OK)

            {

                BitmapImage bmp = new BitmapImage();

                bmp.SetSource(e.ChosenPhoto);

                Image1.Source = bmp;

                images.Add(bmp);

            }

        }

        //PhotoChooserTask completed event handler. Set the image source to the chosen photo and add it to the list of images.

        void photoChooserTask_Completed(object sender, PhotoResult e)

        {

            if (e.TaskResult == TaskResult.OK)

            {

                BitmapImage bmp = new BitmapImage();

                bmp.SetSource(e.ChosenPhoto);

                Image1.Source = bmp;

                images.Add(bmp);

     }

        }

        private void CameraCaptureButton_Click(object sender, RoutedEventArgs e)

        {

            cameraCaptureTask.Show();

        }

        private void PhotoChooserButton_Click(object sender, RoutedEventArgs e)

        {

            photoChooserTask.Show();

        }

 

 

Then add the following initialization code to the constructor public MainPage() after InitializeComponent();

            photoChooserTask = new PhotoChooserTask();

            photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);

            cameraCaptureTask = new CameraCaptureTask();

            cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);

 

 

Finally, add a button for CameraCaptureButton_Click and a button for PhotoChooserButton_Click.  Then run the app and click on those buttons to see CameraCaptureTask and PhotoChooserTask.  The image returned by either task will get added to the slideshow and be displayed as the current image.

 

 

The CTP version of the emulator doesn't come with any photos to import, but you can add some pictures using Internet Explorer.  Launch Internet Explorer, find an image you want to use, then click and hold on the image.  You'll get the option to "save picture".

Comments

  • Anonymous
    December 19, 2010
    Nice and thanks. But MS left out SetAlarmTask.