我是UWP的新手。
我正在将LaunchFileAsync
和DisplayApplicationPicker
从documentation复制到我的项目中:
string imageFile = @"test.pdf";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
if (file != null)
{
// Set the option to show the picker
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
// Launch the retrieved file
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
if (success)
{
// File launched
}
else
{
// File launch failed ====> GETTING TO HERE
}
}
else
{
// Could not find file
}
返回值为false。
为什么?
顺便说一句,调用LaunchFileAsync(file)
(不带options
参数)-在Edge(我的默认PDF应用)中打开pdf文件。
答案 0 :(得分:0)
当DisplayApplicationPicker = true时,LaunchFileAsync失败
我已经测试了上面的代码,但无法重现此问题。请检查您的pdf是否为Content
,并且已在最新的操作系统版本(1909)中测试了该应用。
顺便说一句,调用LaunchFileAsync(file)(不带options参数)-在Edge(我的默认PDF应用)中打开pdf文件
Edge是用于打开pdf文件的默认应用程序。您可以在“设置”页面中对其进行编辑。
设置->应用程序->默认应用程序->按文件类型选择默认应用程序。