1 / 20

Charles Petzold charlespetzold

Launchers and Choosers. Charles Petzold www.charlespetzold.com. Agenda. Launchers Choosers Photo extras Tombstoning. Launchers, Choosers, and Tasks. Tasks target phone's built-in apps Launch Web browser, camera app, etc. Microsoft.Phone.Tasks namespace

kalin
Télécharger la présentation

Charles Petzold charlespetzold

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Launchers and Choosers Charles Petzold www.charlespetzold.com

  2. Agenda • Launchers • Choosers • Photo extras • Tombstoning

  3. Launchers, Choosers, and Tasks • 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

  4. Launcher Tasks

  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 WebBrowserTasktask = new WebBrowserTask(); task.URL = "http://www.nasa.gov"; task.Show();

  8. Chooser Tasks

  9. Snapping a Photo private CameraCaptureTask _task; ... _task = new CameraCaptureTask(); _task.Completed+= new EventHandler<PhotoResult>(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<PhotoResult>(OnSelectionCompleted); _task.Show(); ... private void OnSelectionCompleted(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { Stream photo = e.ChosenPhoto; ... } }

  11. 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 • Extras.xml file registers app for photo extras • Must be named Extras.xml • Build action must be "Content" <Extras> <PhotosExtrasApplication> <Enabled>true</Enabled> </PhotosExtrasApplication> </Extras>

  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" BitmapImagebitmap = new BitmapImage(); bitmap.SetSource(picture.GetImage()); Photo.Source = new WriteableBitmap(bitmap); }

  15. Photo Extras

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

  17. Completed Events • Completed events fire before OnNavigatedTo • If tombstoned data is required in Completed event handler, use application state, not page state <Start App> Launching OnNavigatedTo <Launch PhotoChooserTask> OnNavigatedFrom Deactivated <Return from PhotoChooserTask> 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. Questions? Charles Petzold www.charlespetzold.com

More Related