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.
Now add a Button control to trigger the Launcher and Chooser as shown in the following screen.
XAML Code
- <phone:PhoneApplicationPage
- x:Class="LauncherAndChooser.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
- xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d"
- FontFamily="{StaticResource PhoneFontFamilyNormal}"
- FontSize="{StaticResource PhoneFontSizeNormal}"
- Foreground="{StaticResource PhoneForegroundBrush}"
- SupportedOrientations="Portrait" Orientation="Portrait"
- shell:SystemTray.IsVisible="True">
-
- <Grid x:Name="LayoutRoot" Background="Transparent">
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
- <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
- <Button x:Name="BingMapsTaskBtn" Content="BingMapsTask" HorizontalAlignment="Left" Margin="65,69,0,0" VerticalAlignment="Top" Width="239" Click="BingMapsTaskBtn_Click"/>
- <Button x:Name="CameraCaptureTaskBtn" Content="CameraCaptureTask" HorizontalAlignment="Left" Margin="65,141,0,0" VerticalAlignment="Top" Width="295" Click="CameraCaptureTaskBtn_Click"/>
- <Button x:Name="EmailAddressChooserTaskBtn" Content="EmailAddressChooserTask" HorizontalAlignment="Left" Margin="65,209,0,0" VerticalAlignment="Top" Width="317" Click="EmailAddressChooserTaskBtn_Click"/>
- <Button x:Name="EmailComposeTaskBtn" Content="EmailComposeTask" HorizontalAlignment="Left" Margin="65,281,0,0" VerticalAlignment="Top" Width="274" Click="EmailComposeTaskBtn_Click"/>
- <Button x:Name="PhoneCallTaskBtn" Content="PhoneCallTask" HorizontalAlignment="Left" Margin="65,345,0,0" VerticalAlignment="Top" Width="239" Click="PhoneCallTaskBtn_Click"/>
- <Button x:Name="PhoneNumberChooserTaskBtn" Content="PhoneNumberChooserTask" HorizontalAlignment="Left" Margin="65,403,0,0" VerticalAlignment="Top" Width="343" Click="PhoneNumberChooserTaskBtn_Click"/>
- <Button x:Name="PhotoChooserTask" Content="PhotoChooserTask" HorizontalAlignment="Left" Margin="65,474,0,0" VerticalAlignment="Top" Width="239" Click="PhotoChooserTask_Click"/>
- <Button x:Name="SearchTaskbtn" Content="SearchTask" HorizontalAlignment="Left" Margin="65,541,0,0" VerticalAlignment="Top" Width="239" Click="SearchTaskbtn_Click"/>
- <Button x:Name="AddressChooserTaskBtn" Content="AddressChooserTask" HorizontalAlignment="Left" Margin="65,10,0,0" VerticalAlignment="Top" Width="333" Click="AddressChooserTaskBtn_Click" />
- <Button x:Name="SmsComposeTaskBtn" Content="SmsComposeTask" HorizontalAlignment="Left" Margin="65,613,0,0" VerticalAlignment="Top" Width="239" Click="SmsComposeTaskBtn_Click"/>
- <Button x:Name="WebBrowserTaskBtn" Content="WebBrowserTask" HorizontalAlignment="Left" Margin="65,686,0,0" VerticalAlignment="Top" Width="239" Click="WebBrowserTaskBtn_Click"/>
- </Grid>
- </Grid>
- </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
Go to the code behind page and write the following code. Add the following namespace first:
using Microsoft.Phone.Tasks;
C# Code
AddressChooserTask
- private void AddressChooserTaskBtn_Click(object sender, RoutedEventArgs e)
- {
- AddressChooserTask openTask = new AddressChooserTask();
- openTask.Completed += openTask_Completed;
- openTask.Show();
- }
- void openTask_Completed(object sender, AddressResult e)
- {
- MessageBox.Show(e.Address + "-" + e.DisplayName);
- }
BingMapsTask
- private void BingMapsTaskBtn_Click(object sender, RoutedEventArgs e)
- {
- BingMapsTask openBing = new BingMapsTask();
- openBing.SearchTerm = "Chennai";
- openBing.ZoomLevel = 10;
- openBing.Show();
- }
CameraCaptureTask
- private void CameraCaptureTaskBtn_Click(object sender, RoutedEventArgs e)
- {
- CameraCaptureTask openCameraTask = new CameraCaptureTask();
- openCameraTask.Show();
- }
EmailAddressChooserTask
- private void EmailAddressChooserTaskBtn_Click(object sender, RoutedEventArgs e)
- {
- EmailAddressChooserTask openEmailTask = new EmailAddressChooserTask();
- openEmailTask.Completed += openEmailTask_Completed;
- openEmailTask.Show();
- }
-
- void openEmailTask_Completed(object sender, EmailResult e)
- {
- MessageBox.Show(e.Email);
- }
EmailComposeTask
- private void EmailComposeTaskBtn_Click(object sender, RoutedEventArgs e)
- {
- EmailComposeTask openEmailComposeTask = new EmailComposeTask();
- openEmailComposeTask.To = "toAddress";
- openEmailComposeTask.Subject = "openEmail";
- openEmailComposeTask.Bcc = "bcc";
- openEmailComposeTask.Cc = "cc";
- openEmailComposeTask.Body = "Message Content";
- openEmailComposeTask.Show();
- }
PhoneCallTask
- private void PhoneCallTaskBtn_Click(object sender, RoutedEventArgs e)
- {
- PhoneCallTask openPhoneCall = new PhoneCallTask();
- openPhoneCall.PhoneNumber = "+919442921025";
- openPhoneCall.DisplayName = "Suresh";
- openPhoneCall.Show();
- }
PhoneNumberChooserTask
- private void PhoneNumberChooserTaskBtn_Click(object sender, RoutedEventArgs e)
- {
- PhoneNumberChooserTask openPhoneNumberChooser = new PhoneNumberChooserTask();
- openPhoneNumberChooser.Completed += openPhoneNumberChooser_Completed;
- openPhoneNumberChooser.Show();
- }
-
- void openPhoneNumberChooser_Completed(object sender, PhoneNumberResult e)
- {
- MessageBox.Show(e.PhoneNumber);
- }
PhotoChooserTask
- private void PhotoChooserTask_Click(object sender, RoutedEventArgs e)
- {
- PhotoChooserTask openPhotos = new PhotoChooserTask();
- openPhotos.Completed += openPhotos_Completed;
- openPhotos.Show();
- }
-
- void openPhotos_Completed(object sender, PhotoResult e)
- {
- MessageBox.Show(e.OriginalFileName);
-
- }
SearchTask
- private void SearchTaskbtn_Click(object sender, RoutedEventArgs e)
- {
- SearchTask openSearch = new SearchTask();
- openSearch.SearchQuery = "C sharp corner";
-
- openSearch.Show();
-
- }
SmsComposeTask
- private void SmsComposeTaskBtn_Click(object sender, RoutedEventArgs e)
- {
- SmsComposeTask openSMSTask = new SmsComposeTask();
- openSMSTask.Body = "Message Body";
- openSMSTask.To = "+919442921025";
- openSMSTask.Show();
- }
WebBrowserTask
- private void WebBrowserTaskBtn_Click(object sender, RoutedEventArgs e)
- {
- WebBrowserTask openBrowser = new WebBrowserTask();
- openBrowser.Uri = new Uri("http://www.windowsapptutorials.wordpress.com/");
- openBrowser.Show();
- }
Now run your application. The output looks as in the following screen.