Search code examples
c#windows-phone-8.1storagewindows-10imaging

How can I open an image in the default photos app?


I have an app that captures images from the device's camera and saves them as StorageFiles to a folder in my app's roaming data. I've been trying to make a page that will open the image and show a preview, but I've been having many problems doing that, so I want to just open the image in the default photos app. However, I can't find any way to do that. Using await Launcher.LaunchUriAsync(new Uri(@"ms-appdata:///roaming/folder/img.jpg")); asks if I want to search for an app in the Store (searches for "ms-appdata"). Does the native Photos app for Windows (Phone) have a dedicated URI scheme? Also, I am targeting Windows 10 with this app, so the URI schemes (if any) may have changed.


Solution

  • Launcher.LaunchUriAsync is for launching an application using the URI scheme, this is not what you want.

    Instead you'll want to launch an app based on a file:
    Get the image as a StorageFile

    var imageFile = await StorageFile.GetFileFromPathAsync(@"ms-appdata:///roaming/folder/img.jpg");
    

    Then you tell the OS to launch an app to handle that file. It's then up to the user to choose which app to handle the image file:

    var success = await Windows.System.Launcher.LaunchFileAsync(imageFile);
    

    You can read more about "launching" files here.