Search code examples
uwpwindows-10-mobile

Windows.System.LaunchUriAsync throws exception only on Windows 10 mobile


I am developing a UWP app which is targeted on both Desktop and Mobile. At some point in the app the following code is used

var success = await Windows.System.Launcher.LaunchUriAsync(new Uri(uri), new Windows.System.LauncherOptions { ContentType = mimeType });

This code works as it should on Desktop. For example when the URI is that of an image (like this one https://support.files.wordpress.com/2009/07/pigeony.jpg that I have tried) the Photos app is launched and the photo is displayed.

On mobile however the exact same code, with the exact same arguments throws an Exception.

Message: The method or operation is not implemented

StackTrace: at Windows.System.LauncherOptions.put_ContentType(String value) at MyApp.Services.PresentationService.d__7.MoveNext()

The problem seems to be with the LauncherOptions because if I remove them from the call the image opens normally in the browser. (However this is not acceptable functionality, I need to launch the appropriate application).

According to documentation there should be no differences between windows 10 and windows 10 mobile concerning the LaunchUriAsync method. Does anybody know what is going on?


Solution

  • According to documentation there should be no differences between windows 10 and windows 10 mobile concerning the LaunchUriAsync method

    Actually, the LauncherOptions.ContentType property is only implemented on Desktop devices, see Remark in here

    Important This property is only implemented on Desktop devices.

    -

    However this is not acceptable functionality, I need to launch the appropriate application

    Currently, there is no simple/direct way to implement this on Mobile, there are some workarounds, for example: Download Images to Local folder/Picture folder, opening Photo apps or showing them in your app

    var options = new Windows.System.LauncherOptions();
    var df = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily;
    if (df == "Windows.Desktop")
    {
                options.ContentType = "image/jpeg";
    }
    else
    {
                //Omitted, save network images into Picture folder
    
                uriToLaunch = "ms-photos:///"; //Launch Photo app
    }
    var uri = new Uri(uriToLaunch);
    // Launch the URI with the content type
    var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
    

    BTW, please submit your feature request using the Feedback app, this is a good way to let MS know what users/developers need.