简体   繁体   English

Uri激活为“ ms-appdata:/// local /”

[英]Uri activation to “ms-appdata:///local/”

Running this code below gives me this unexpected result: 在下面运行此代码将为我带来意外的结果:

在此处输入图片说明

    private async void OpenItemAppBarBtn_Click(object sender, RoutedEventArgs e)
    {
        MediaViewModel media = MyListView.SelectedItem as MediaViewModel;

        if (media.VidOrPic)
        {
            var uriString = "ms-appdata:///local/" + media.Name + ".mp4";
            Uri muUri = new Uri(uriString);
            Launcher.LaunchUriAsync(new Uri(uriString, UriKind.RelativeOrAbsolute));
        }
        else
        {
            var uriString = "ms-appdata:///local/" + media.Name + ".jpeg";
            Uri muUri = new Uri(uriString);
            Launcher.LaunchUriAsync(new Uri(uriString, UriKind.RelativeOrAbsolute));
        }   
    }

UriString Content: UriString内容:

在此处输入图片说明

The Launcher.LaunchUriAsync method always shows the application picker, if no default application is associated with the Uri you provide. 如果没有默认应用程序与您提供的Uri关联,则Launcher.LaunchUriAsync方法始终显示应用程序选择器。

However, there's an overload : 但是,有一个重载

Launcher.LaunchUriAsync(Uri, LauncherOptions)

The launcher options allow you to set a property called DisplayApplicationPicker . 启动器选项允许您设置一个名为DisplayApplicationPicker的属性。 If the default app is defined and you set this value to true, using the overload, the application will start directly, without displaying the application picker. 如果定义了默认应用程序, 并且您将此值设置为true,则使用重载,该应用程序将直接启动,而不显示应用程序选择器。

to run the file use Launcher.LaunchFileAsync, not Launcher.LaunchUriAsync 要运行文件,请使用Launcher.LaunchFileAsync,而不是Launcher.LaunchUriAsync

var uriString = "ms-appdata:///local/" + media.Name + ".mp4";
Uri muUri = new Uri(uriString);
var file = await StorageFile.GetFileFromApplicationUriAsync(muUri);
await Launcher.LaunchFileAsync(file);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM