In my last article Part 69 - Windows Phone - Launch Application from Picture Hub I talked about lauching app from Picture Hub. In this article I will discuss on how to Launch Application from picture viewer.
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_Viewer" 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 is launched from Picture Viewer, parameter "token" is to the application via deep link URI.The "token" parameter corresponds to the picture that your application is launched from and it will be used to disply the image in the image control using below code snippet.
Place below code in the MainPage.xaml.cs.
protected override void OnNavigatedTo(NavigationEventArgs e) { IDictionary<string, string> queryStrings = this.NavigationContext.QueryString; if (queryStrings.ContainsKey("token")) { // Retrieve the picture from the media library using the token passed to the application. MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken(queryStrings["token"]); BitmapImage bitmap = new BitmapImage(); bitmap.CreateOptions = BitmapCreateOptions.None; bitmap.SetSource(picture.GetImage()); WriteableBitmap picLibraryImage = new WriteableBitmap(bitmap); appFromPictureViewer.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 app... menu bar item.
On clicking of apps you will get your app, now tap on your app.
Your app will be opened with the image selected in the Camera Roll or albums.
Below image depicts the Steps to follow to test it.
Step 1 Step 2 Step 3
This ends the article of launching application from picture viewer.
|