Presentation is loading. Please wait.

Presentation is loading. Please wait.

Charles Petzold www.charlespetzold.com Launchers and Choosers.

Similar presentations


Presentation on theme: "Charles Petzold www.charlespetzold.com Launchers and Choosers."— Presentation transcript:

1 Charles Petzold www.charlespetzold.com Launchers and Choosers

2 Agenda Launchers Choosers Photo extras Tombstoning

3 Tasks target phone's built-in apps –Launch Web browser, camera app, etc. –Microsoft.Phone.Tasks namespace Some tasks are activated with launchers –Launches app but doesn't return data –e.g., compose e-mail or place phone call Others are activated with choosers –Launches app and returns data –e.g., snap a photo or choose an e-mail address Launchers, Choosers, and Tasks

4 Launcher Tasks ClassDescription EmailComposeTask Launches the e-mail app MarketPlaceDetailTask Launches the marketplace app showing a product detail MarketPlaceHubTask Launches the marketplace app showing the hub MarketPlaceReviewTask Launches the marketplace app showing a product review MarketPlaceSearchTask Launches the marketplace app showing search results MediaPlayerLauncher Launches the media player app PhoneCallTask Launches the phone app SearchTask Launches the search app SmsComposeTask Launches the text-messaging app WebBrowserTask Launches the Web browser

5 Launching a Phone Task PhoneCallTask task = new PhoneCallTask(); task.PhoneNumber = "8659685528"; task.DisplayName = "Wintellect"; task.Show();

6 Launching an E-Mail Task EmailComposeTask task = new EmailComposeTask(); task.To = "jeffpro@foo.com"; task.Cc = "jeffpro@bar.com"; task.Body = "This is a test"; task.Subject = "Test Message"; task.Show();

7 Launching a WebBrowserTask WebBrowserTask task = new WebBrowserTask(); task.URL = "http://www.nasa.gov"; task.Show();

8 Chooser Tasks ClassDescription CameraCaptureTask Launches the camera app and returns a photo EmailAddressChooserTask Allows the user to choose an e-mail address from the contacts list PhoneNumberChooserTask Allows the user to choose a phone number from the contacts list PhotoChooserTask Allows the user to choose a photo from the photos app SaveEmailAddressTask Allows the user to save an e-mail address in the contacts list (returns completion indicator but no data) SavePhoneNumberTask Allows the user to save a phone number in the contacts list (returns completion indicator but no data)

9 Snapping a Photo private CameraCaptureTask _task;... _task = new CameraCaptureTask(); _task.Completed += new EventHandler (OnCaptureCompleted); _task.Show();... private void OnCaptureCompleted(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { Stream photo = e.ChosenPhoto;... }

10 Choosing a Photo private PhotoChooseTask _task;... _task = new PhotoChooserTask(); _task.Completed += new EventHandler (OnSelectionCompleted); _task.Show();... private void OnSelectionCompleted(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { Stream photo = e.ChosenPhoto;... }

11 demo Launchers and Choosers

12 Photo Extras Applications invoked through "extras…" item in picture library menu –Item only appears if one or more extras are installed Work as stand-alone apps, too

13 Extras.xml file registers app for photo extras –Must be named Extras.xml –Build action must be "Content" Extras.xml true

14 Retrieving a Photo protected override void OnNavigatedTo(NavigationEventArgs e) { if (NavigationContext.QueryString.ContainsKey("token")) { // If app was invoked through Extras menu, grab the photo MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken (NavigationContext.QueryString["token"]); // Display the photo in XAML Image object named "Photo" BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(picture.GetImage()); Photo.Source = new WriteableBitmap(bitmap); }

15 demo Photo Extras

16 Some tasks may not cause tombstoning –CameraCaptureTask –EmailAddressChooserTask –MediaPlayerLauncher –PhoneNumberChooserTasks –PhotoChooserTask Other tasks do cause app to be tombstoned All apps should support tombstoning! Tombstoning

17 Completed events fire before OnNavigatedTo If tombstoned data is required in Completed event handler, use application state, not page state Completed Events Launching OnNavigatedTo OnNavigatedFrom Deactivated Activated PhotoChooserTask.Completed OnNavigatedTo Launching OnNavigatedTo OnNavigatedFrom Deactivated Activated PhotoChooserTask.Completed OnNavigatedTo

18 This Works // PhotoChooserTask.Completed event handler private void OnSelectionCompleted(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { // Retrieve tombstoned data from application state int index = (int)PhoneApplicationService.Current.State["Index"];... }

19 This Does Not // PhotoChooserTask.Completed event handler private void OnSelectionCompleted(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { // Retrieve tombstoned data from page state int index = (int)this.State["Index"];... }

20 Charles Petzold www.charlespetzold.com Questions?


Download ppt "Charles Petzold www.charlespetzold.com Launchers and Choosers."

Similar presentations


Ads by Google