How to use the share media task for Windows Phone 8

August 19, 2014

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 only

Use the share photo/video task to launch the share picker from your app. The share picker allows your app to share a media item with one of the media-sharing apps that are installed on the phone. To learn more about writing a photo-sharing app that appears inside the share picker, see Extending the share picker for Windows Phone 8.

NoteNote:

In the current release, only image files can be shared using this API.

By using Launchers, you help provide a consistent user experience throughout the Windows Phone platform. For more information, see Launchers and Choosers for Windows Phone 8.

To use the share media task

  1. Add the following statement to your code.

    
    using Microsoft.Phone.Tasks;
    
    
    
  2. This example will use the photo chooser task to allow the user to select or capture a photo to share. Declare the task object. It must have page scope, so declare it in your page before the constructor.

    
    CameraCaptureTask cameraCaptureTask = new CameraCaptureTask();
    
    
    
  3. Add the following code to your page constructor. This code initializes the task object, and identifies the method to run after the user completes the task.

    
    cameraCaptureTask.Completed += cameraCaptureTask_Completed;
    
    
    
  4. Launch the photo chooser task to allow the user to select or capture a photo. Add the following code to your application wherever you need it, such as in a button click event. To test this procedure, you can put the code in the page constructor.

    
    cameraCaptureTask.Show();
    
    
    
  5. Add the code for the completed event handler to your page. This code runs after the user selects a photo. The result is an AddressResult object that contains the path to the selected photo. Use this value to set the FilePath property of the ShareMediaTask object and then call Show to launch the sharing dialog where the user can select services with which to share the item.

    
           void cameraCaptureTask_Completed(object sender, PhotoResult e)
           {
    	        if(e.TaskResult == TaskResult.OK)
               {
                   ShowShareMediaTask(e.OriginalFileName);
               }
           }
           void ShowShareMediaTask(string path)
           {
               ShareMediaTask shareMediaTask = new ShareMediaTask();
               shareMediaTask.FilePath = path;
               shareMediaTask.Show();
           }
    
    
    

Show:
© 2014 Microsoft