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

时间:2015-09-03 15:47:17

标签: c# uwp

下面运行此代码会给我带来意想不到的结果:

enter image description here

    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内容:

enter image description here

2 个答案:

答案 0 :(得分:1)

Launcher.LaunchUriAsync方法始终显示应用程序选择器,如果没有默认应用程序与您提供的Uri关联。

但是,有一个overload

Launcher.LaunchUriAsync(Uri, LauncherOptions)

启动器选项允许您设置名为DisplayApplicationPicker的属性。如果默认应用定义为,则将此值设置为true,使用重载,应用程序将直接启动,而不显示应用程序选择器。

答案 1 :(得分:1)

运行文件使用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);