Windows Phone Tasks – Launchers and Choosers

 

In this part we are going to discussed about the Windows Phone Tasks – Launchers and Choosers.
image
Windows Phone tasks API allows you to invoke native tasks (phone’s applications) form your application using managed API, such as PhoneCallTask, EmailComposeTask, SmsComposeTask and MarketplaceSearchTask and so on.
Launchers and Choosers are straightforward to associate with your application.

See the following code snippet for Launchers

  1:  private void btnEmailComposeTask_Click(object sender, RoutedEventArgs e)
  2:         {
  3:             EmailComposeTask oEct = new EmailComposeTask();
  4:             oEct.To = "pavan.pareta@gmail.com";
  5:             oEct.Show();
  6:         }
  7: 
  8:         private void btnMarketplaceDetailTask_Click(object sender, RoutedEventArgs e)
  9:         {
 10:             MarketplaceDetailTask oMdt = new MarketplaceDetailTask();
 11:             oMdt.ContentType = MarketplaceContentType.Applications;
 12:             oMdt.ContentIdentifier = "1fa6b3b1-11f0-4265-ab3d-ac70df5edabc";
 13:             oMdt.Show();
 14:         }
 15: 
 16:         private void btnMarketplaceHubTask_Click(object sender, RoutedEventArgs e)
 17:         {
 18:             MarketplaceHubTask oMht = new MarketplaceHubTask();
 19:             oMht.ContentType = MarketplaceContentType.Music;
 20:             oMht.Show();
 21:         }
 22: 
 23:         private void btnMarketplaceReviewTask_Click(object sender, RoutedEventArgs e)
 24:         {
 25:             MarketplaceReviewTask oMrt = new MarketplaceReviewTask();
 26:             oMrt.Show();
 27:         }
 28: 
 29:         private void btnMarketplaceSearchTask_Click(object sender, RoutedEventArgs e)
 30:         {
 31:             MarketplaceSearchTask oMst = new MarketplaceSearchTask();
 32:             oMst.ContentType = MarketplaceContentType.Applications;
 33:             oMst.SearchTerms = "Games";
 34:             oMst.Show();
 35:         }
 36: 
 37:         private void btnMediaPlayerLauncher_Click(object sender, RoutedEventArgs e)
 38:         {
 39:             MediaPlayerLauncher oMpl = new MediaPlayerLauncher();
 40:             oMpl.Controls = MediaPlaybackControls.All;
 41:             oMpl.Media = new Uri("http://ecn.channel9.msdn.com/o9/ch9/1be6/d5819645-cf1e-4542-bb9d-9e10015a1be6/day01part1_ch9.wmv");
 42:             oMpl.Show();
 43:         }
 44: 
 45:         private void btnPhoneCallTask_Click(object sender, RoutedEventArgs e)
 46:         {
 47:             PhoneCallTask oPct = new PhoneCallTask();
 48:             oPct.PhoneNumber = "1234567890";
 49:             oPct.Show();
 50:         }
 51: 
 52:         private void btnSearchTask_Click(object sender, RoutedEventArgs e)
 53:         {
 54:             SearchTask oSt = new SearchTask();
 55:             oSt.SearchQuery = "Game";
 56:             oSt.Show();
 57:         }
 58: 
 59:         private void btnSmsComposeTask_Click(object sender, RoutedEventArgs e)
 60:         {
 61:             SmsComposeTask oSct = new SmsComposeTask();
 62:             oSct.To = "12345";
 63:             oSct.Body = "Hi! This Windows Phone";
 64:             oSct.Show();
 65:         }
 66: 
 67:         private void btnWebBrowserTask_Click(object sender, RoutedEventArgs e)
 68:         {
 69:             WebBrowserTask oWbt = new WebBrowserTask();
 70:             oWbt.Uri = new Uri("http://www.http://windows-mobile-dev.blogspot.in/");
 71:             oWbt.Show();
 72:         }

Code snippet for.Choosers

  1: private void btnCameraCaptureTask_Click(object sender, RoutedEventArgs e)
  2:         {
  3:             CameraCaptureTask oCct = new CameraCaptureTask();
  4:             oCct.Completed += (s, evnt) =>
  5:             {
  6:                 if (evnt.Error == null && evnt.TaskResult == TaskResult.OK)
  7:                 {
  8:                     BitmapImage bmpImage = new BitmapImage();
  9:                     bmpImage.SetSource(evnt.ChosenPhoto);
 10:                     ImageBrush imb = new ImageBrush();
 11:                     imb.ImageSource = bmpImage;
 12:                     LayoutRoot.Background = imb;
 13:                 }
 14:             };
 15:             oCct.Show();
 16:         }
 17: 
 18:         private void btnEmailId_Click(object sender, RoutedEventArgs e)
 19:         {
 20:             EmailAddressChooserTask oEact = new EmailAddressChooserTask();
 21:             oEact.Completed += (s, evnt) =>
 22:                 {
 23:                     if (evnt.Error == null && evnt.TaskResult == TaskResult.OK)
 24:                     {
 25:                         MessageBox.Show("Name:" + evnt.DisplayName + "\nEmail Id:" + evnt.Email);
 26:                     }
 27: 
 28:                 };
 29:             oEact.Show();
 30:         }
 31: 
 32:         private void btnPhoneNumberChooserTask_Click(object sender, RoutedEventArgs e)
 33:         {
 34:             PhoneNumberChooserTask oPnct = new PhoneNumberChooserTask();
 35:             oPnct.Completed += (s, evnt) =>
 36:             {
 37:                 if (evnt.Error == null && evnt.TaskResult == TaskResult.OK)
 38:                 {
 39:                     MessageBox.Show("Name:" + evnt.DisplayName + "\nPhone Number:" + evnt.PhoneNumber);
 40:                 }
 41: 
 42:             };
 43:             oPnct.Show();
 44:         }
 45: 
 46:         private void btnPhotoChooserTask_Click(object sender, RoutedEventArgs e)
 47:         {
 48:             PhotoChooserTask oPct = new PhotoChooserTask();
 49:             oPct.Completed += (s, evnt) =>
 50:             {
 51:                 if (evnt.Error == null && evnt.TaskResult == TaskResult.OK)
 52:                 {
 53:                     BitmapImage bmpImage = new BitmapImage();
 54:                     bmpImage.SetSource(evnt.ChosenPhoto);
 55:                     ImageBrush imb = new ImageBrush();
 56:                     imb.ImageSource = bmpImage;
 57:                     LayoutRoot.Background = imb;
 58:                 }
 59:             };
 60:             oPct.Show();
 61:         }
 62: 
 63:         private void btnSaveEmailAddressTask_Click(object sender, RoutedEventArgs e)
 64:         {
 65:             SaveEmailAddressTask oSeat = new SaveEmailAddressTask();
 66:             oSeat.Completed += (s, evnt) =>
 67:             {
 68:                 if (evnt.Error == null && evnt.TaskResult == TaskResult.OK)
 69:                 {
 70:                     MessageBox.Show("TaskResult is:" + evnt.TaskResult);
 71:                 }
 72:             };
 73:             oSeat.Show();
 74:         }
 75: 
 76:         private void btnSavePhoneNumberTask_Click(object sender, RoutedEventArgs e)
 77:         {
 78:             SavePhoneNumberTask oSeat = new SavePhoneNumberTask();
 79:             oSeat.Completed += (s, evnt) =>
 80:             {
 81:                 if (evnt.Error == null && evnt.TaskResult == TaskResult.OK)
 82:                 {
 83:                     MessageBox.Show("TaskResult is:" + evnt.TaskResult);
 84:                 }
 85:             };
 86:             oSeat.Show();
 87:         }

Download source code here

Happy CodingThumbs up

Advertisements

About Pavan Pareta

My name is Pavan Pareta, I enjoy computers and general technology. I am more interested in the areas of Computer Security, Programming and developing innovative s/w for Windows Mobile and Windows Phone 7. I like MS Technology and support open-source software, because I believe it plays a major role in knowledge sharing and exchange of ideas, which effectively leads to better software. Additionally, I am a follower of the KISS (Keep It Simple Stupid) philosophy. I Love C#.NET and recently I am fall in love with Silverlight :) Introduce to my machine My main workstation is a Intel Pentium Core Duo and my primary operating system is Windows 7.
This entry was posted in Windows Phone, Windows Phone 7. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s