Windows Phone 8 Launcher and Chooser Task

In this article we will see a Launcher and Chooser in Windows Phone 8.

The following is the list of launchers and choosers in Windows Phone 8.

AddressChooserTask Allows an application to launch the Contact application
BingMapsTask Allows an application to launch the Bing Maps
CameraCaptureTask Allows an application to launch the Camera application
EmailAddressChooserTask Allows an application to launch the Contacts application
EmailComposeTask Allows an application to launch the Email application
PhoneCallTask Allows an application to launch the Phone application
PhoneNumberChooserTask Allows an application to launch the Phone Contact application
PhotoChooserTask Allows an application to launch the Photo Chooser application
SearchTask Allows an application to launch the Web Search application
SmsComposeTask Allows an application to launch the Messaging application to compose new SMS
WebBrowserTask Allows an application to launch the browser

Let us see the procedure for doing this in Windows Phone 8. Create a new project with a valid name. Once everything is ready our project looks as in the following screen.

project screen

Now add a Button control to trigger the Launcher and Chooser as shown in the following screen.

add button

XAML Code

  1. <phone:PhoneApplicationPage  
  2.     x:Class="LauncherAndChooser.MainPage"  
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"  
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"  
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
  9.     mc:Ignorable="d"  
  10.     FontFamily="{StaticResource PhoneFontFamilyNormal}"  
  11.     FontSize="{StaticResource PhoneFontSizeNormal}"  
  12.     Foreground="{StaticResource PhoneForegroundBrush}"  
  13.     SupportedOrientations="Portrait" Orientation="Portrait"  
  14.     shell:SystemTray.IsVisible="True">  
  15.     <!--LayoutRoot is the root grid where all page content is placed-->  
  16.     <Grid x:Name="LayoutRoot" Background="Transparent">  
  17.         <Grid.RowDefinitions>  
  18.             <RowDefinition Height="Auto"/>  
  19.             <RowDefinition Height="*"/>  
  20.         </Grid.RowDefinitions>  
  21.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">  
  22.             <Button x:Name="BingMapsTaskBtn" Content="BingMapsTask" HorizontalAlignment="Left" Margin="65,69,0,0" VerticalAlignment="Top" Width="239" Click="BingMapsTaskBtn_Click"/>  
  23.             <Button x:Name="CameraCaptureTaskBtn" Content="CameraCaptureTask" HorizontalAlignment="Left" Margin="65,141,0,0" VerticalAlignment="Top" Width="295" Click="CameraCaptureTaskBtn_Click"/>  
  24.             <Button x:Name="EmailAddressChooserTaskBtn" Content="EmailAddressChooserTask" HorizontalAlignment="Left" Margin="65,209,0,0" VerticalAlignment="Top" Width="317" Click="EmailAddressChooserTaskBtn_Click"/>  
  25.             <Button x:Name="EmailComposeTaskBtn" Content="EmailComposeTask" HorizontalAlignment="Left" Margin="65,281,0,0" VerticalAlignment="Top" Width="274" Click="EmailComposeTaskBtn_Click"/>  
  26.             <Button x:Name="PhoneCallTaskBtn" Content="PhoneCallTask" HorizontalAlignment="Left" Margin="65,345,0,0" VerticalAlignment="Top" Width="239" Click="PhoneCallTaskBtn_Click"/>  
  27.             <Button x:Name="PhoneNumberChooserTaskBtn" Content="PhoneNumberChooserTask" HorizontalAlignment="Left" Margin="65,403,0,0" VerticalAlignment="Top" Width="343" Click="PhoneNumberChooserTaskBtn_Click"/>  
  28.             <Button x:Name="PhotoChooserTask" Content="PhotoChooserTask" HorizontalAlignment="Left" Margin="65,474,0,0" VerticalAlignment="Top" Width="239" Click="PhotoChooserTask_Click"/>  
  29.             <Button x:Name="SearchTaskbtn" Content="SearchTask" HorizontalAlignment="Left" Margin="65,541,0,0" VerticalAlignment="Top" Width="239" Click="SearchTaskbtn_Click"/>  
  30.             <Button x:Name="AddressChooserTaskBtn" Content="AddressChooserTask" HorizontalAlignment="Left" Margin="65,10,0,0" VerticalAlignment="Top" Width="333" Click="AddressChooserTaskBtn_Click" />  
  31.             <Button x:Name="SmsComposeTaskBtn" Content="SmsComposeTask" HorizontalAlignment="Left" Margin="65,613,0,0" VerticalAlignment="Top" Width="239" Click="SmsComposeTaskBtn_Click"/>  
  32.             <Button x:Name="WebBrowserTaskBtn" Content="WebBrowserTask" HorizontalAlignment="Left" Margin="65,686,0,0" VerticalAlignment="Top" Width="239" Click="WebBrowserTaskBtn_Click"/>  
  33.         </Grid>  
  34.     </Grid>  
  35. </phone:PhoneApplicationPage>   
Now go to the code behind page. We need to open the WMAppManifest file and enable the following capabilities as shown in the following screen.
  • ID_CAP_CONTACTS
  • ID_CAP_MAP
  • ID_CAP_MEDIA
  • ID_CAP_ISV_CAMERA
  • ID_CAP_WEBBROWSERCOMPONENT
  • ID_CAP_PHONEDIALER

code behind page

Go to the code behind page and write the following code. Add the following namespace first:

using Microsoft.Phone.Tasks;

C# Code

AddressChooserTask

  1. private void AddressChooserTaskBtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    AddressChooserTask openTask = new AddressChooserTask();  
  4.    openTask.Completed += openTask_Completed;  
  5.    openTask.Show();  
  6. }  
  7. void openTask_Completed(object sender, AddressResult e)  
  8. {  
  9.    MessageBox.Show(e.Address + "-" + e.DisplayName);  
  10. }  

 

BingMapsTask

  1. private void BingMapsTaskBtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    BingMapsTask openBing = new BingMapsTask();  
  4.    openBing.SearchTerm = "Chennai";  
  5.    openBing.ZoomLevel = 10;  
  6.    openBing.Show();  
  7. }  
CameraCaptureTask
  1. private void CameraCaptureTaskBtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    CameraCaptureTask openCameraTask = new CameraCaptureTask();  
  4.    openCameraTask.Show();  
  5. }  
EmailAddressChooserTask
  1. private void EmailAddressChooserTaskBtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    EmailAddressChooserTask openEmailTask = new EmailAddressChooserTask();  
  4.    openEmailTask.Completed += openEmailTask_Completed;  
  5.    openEmailTask.Show();  
  6. }  
  7.   
  8. void openEmailTask_Completed(object sender, EmailResult e)  
  9. {  
  10.    MessageBox.Show(e.Email);  
  11. }  
EmailComposeTask
  1. private void EmailComposeTaskBtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    EmailComposeTask openEmailComposeTask = new EmailComposeTask();  
  4.    openEmailComposeTask.To = "toAddress";  
  5.    openEmailComposeTask.Subject = "openEmail";  
  6.    openEmailComposeTask.Bcc = "bcc";  
  7.    openEmailComposeTask.Cc = "cc";  
  8.    openEmailComposeTask.Body = "Message Content";  
  9.    openEmailComposeTask.Show();  
  10. }  
PhoneCallTask
  1. private void PhoneCallTaskBtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    PhoneCallTask openPhoneCall = new PhoneCallTask();  
  4.    openPhoneCall.PhoneNumber = "+919442921025";  
  5.    openPhoneCall.DisplayName = "Suresh";  
  6.    openPhoneCall.Show();  
  7. }  
PhoneNumberChooserTask
  1. private void PhoneNumberChooserTaskBtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    PhoneNumberChooserTask openPhoneNumberChooser = new PhoneNumberChooserTask();  
  4.    openPhoneNumberChooser.Completed += openPhoneNumberChooser_Completed;  
  5.    openPhoneNumberChooser.Show();  
  6. }  
  7.   
  8. void openPhoneNumberChooser_Completed(object sender, PhoneNumberResult e)  
  9. {  
  10.    MessageBox.Show(e.PhoneNumber);  
  11. }  
PhotoChooserTask
  1. private void PhotoChooserTask_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    PhotoChooserTask openPhotos = new PhotoChooserTask();  
  4.    openPhotos.Completed += openPhotos_Completed;  
  5.    openPhotos.Show();  
  6. }  
  7.   
  8. void openPhotos_Completed(object sender, PhotoResult e)  
  9. {  
  10.    MessageBox.Show(e.OriginalFileName);  
  11.    //write the code to view or process the selected photo/image  
  12. }  
SearchTask
  1. private void SearchTaskbtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    SearchTask openSearch = new SearchTask();  
  4.    openSearch.SearchQuery = "C sharp corner";  
  5.    //here you write your own query to search  
  6.    openSearch.Show();  
  7.   
  8. }  
SmsComposeTask
  1. private void SmsComposeTaskBtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    SmsComposeTask openSMSTask = new SmsComposeTask();  
  4.    openSMSTask.Body = "Message Body";  
  5.    openSMSTask.To = "+919442921025";  
  6.    openSMSTask.Show();  
  7. }  
WebBrowserTask
  1. private void WebBrowserTaskBtn_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.    WebBrowserTask openBrowser = new WebBrowserTask();  
  4.    openBrowser.Uri = new Uri("http://www.windowsapptutorials.wordpress.com/");  
  5.    openBrowser.Show();  
  6. }  
Now run your application. The output looks as in the following screen.

run your application

screen

output