In my last two articles listed below I talked about Picutre Hub and Picture Viewer in Windows Phone.
Part 69 - Windows Phone - Launch Application from Picture Hub
Part 70 - Windows Phone - Launch application from Picture Viewer
In this article I will discuss how to put your app in Share option(Shown Below) of Picture Viewer .

On click of Share you will get list of apps using which you can use the selected pic in your app. In the below picture my app name is "Share Picker".

Let's see how we can do this.
Step 1: Create a new Silverlight Windows Phone project.
Step 2: Provide name to the project and you will promepted to select Target Framework Version. Select Windows Phone 7.1.
This feature is supported in Windows Phone 7.1 only so make sure you choose Target Windows Phone Version as Windows Phone 7.1.
Step 3: Open WMAppManifest.xml present in Properties folder. Place below code after Tokens element.
<Extensions> <Extension ExtensionName="Photos_Extra_Share" ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5632}"TaskID="_default" /> </Extensions>
ExtensionName should be Photos_Extra_Hub which is picture extension identifier.
ConsumerID "5B04B775-356B-4AA0-AAF8-6491FFEA5632" is used by each pictures extension
Step 4: Add a image control like below inside ContentPanel of MainPage.xaml.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <Image Height="550" HorizontalAlignment="Left" Margin="6,18,0,0" Name="appFromPictureViewer" Stretch="Fill"VerticalAlignment="Top" Width="450" /> </Grid>
Step 5: When application launches from Share option of Picture Viewer, parameter FieldId is passed to the application by deep link URI. Using the FieldId parameter picture can be displayed in the application.
In the below code snippet FieldId retrieves the picture from media library then you can create bitmap image to display in the image control placed inside ContentPanel of MainPage.xaml.
protected override void OnNavigatedTo(NavigationEventArgs e) { IDictionary<string, string> queryStrings = this.NavigationContext.QueryString; if (queryStrings.ContainsKey("FileId")) { MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken(queryStrings["FileId"]); BitmapImage bitmap = new BitmapImage();
bitmap.CreateOptions = BitmapCreateOptions.None; bitmap.SetSource(picture.GetImage());
WriteableBitmap picLibraryImage = new WriteableBitmap(bitmap); retrievePic.Source = picLibraryImage; } }
Step 6: Now run the application on Device. The emulator doesn't have access to picture applications.
Once the application is deployed, disconnect the device.
Go to start screen, tap Pictures, tap Camera Roll or albums, select picture, tap on thumbnail to open it.
Now tap on 3 dots of application bar to view menu bar where you will get Share... menu bar item.
On clicking of Share... you will get your app listed, now tap on your app.
Your app will be opened with the image selected from the Camera Roll or albums.
You can put your app in app... option as well as Share... by declaring two Extension element inside Extensions element in WMAppManifest.xml. <Extensions>
<Extension ExtensionName="Photos_Extra_Viewer" ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5632}" TaskID="_default" />
<Extension ExtensionName="Photos_Extra_Hub" ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5632}" TaskID="_default" />
</Extensions> Follow certification rules 6.7 – Applications That Extend the Share Picker
when you are working with launching apps using Share... option of Picture Viewer. This ends the article of launching application using Share... option of Picture Viewer.
|