How to use the share media task for Windows Phone 8

How to use the share media task for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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.

    
    Imports 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.

    
    Dim cameraCaptureTask As 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.

    
    AddHandler cameraCaptureTask.Completed, AddressOf 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.

    
    Private Sub cameraCaptureTask_Completed(sender As Object, e As PhotoResult)
    
        If e.TaskResult = TaskResult.OK Then
            ShowShareMediaTask(e.OriginalFileName)
        End If
    End Sub
    
    Private Sub ShowShareMediaTask(path As String)
    
        Dim shareMediaTask As ShareMediaTask = New ShareMediaTask()
        shareMediaTask.FilePath = path
        shareMediaTask.Show()
    End Sub
    
    
    

Show:
© 2017 Microsoft