如何检测默认的pdfviewer并在Windows Phone中打开PDF

时间:2014-07-30 14:44:22

标签: c# pdf windows-phone-8 windows-phone

我正在尝试在Windows Phone 8中下载并打开pdf文件。当任何pdf查看器(Adobe,MS PDF Reader等)出现在手机上时代码成功运行。

protected async void openPDFFile(string path)
{
    try
    {
        // Access isolated storage.
        StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

        // Access the bug query file.
        StorageFile pdfFile = await local.GetFileAsync(path);
        if (pdfFile != null)
        {
            // Launch the pdf file.
            IAsyncOperation<bool> success = Windows.System.Launcher.LaunchFileAsync(pdfFile);

            if (await success)
            {
                // File launched
                System.Diagnostics.Debug.WriteLine("Successfully Open.");
            }
            else
            {
                // File launch failed
                System.Diagnostics.Debug.WriteLine("Failed to open.");
            }
        }
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine("exception: " + ex.Message);
    }
}

但是当手机上没有pdf查看器时,它正在执行相同的成功代码块,即

if (await success)
{
   // File launched
   System.Diagnostics.Debug.WriteLine("Successfully Open.");
}

并打开Windows Phone系统消息框,可以在系统识别之前检测到它,以便我在这里显示我自己/自定义创建的消息框吗?因为在没有点击windows phone系统消息框,我希望用户在其他页面上重定向。

有没有办法在LaunchFileAsync(filepath)方法之前检测pdf查看器应用程序是否存在?

任何人都可以建议我如何获得解决方案。

有人可以指导我如何使用LaunchFileAsync以下的方法吗?在MSDN中,它声明此方法支持最低手机:: Windows Phone 8.1 。 Windows Phone 8有什么类似的吗?

LaunchFileAsync(IStorageFile, LauncherOptions)

1 个答案:

答案 0 :(得分:0)

不幸的是,LaunchFileAsync的'true'返回值只是意味着成功执行了启动此文件的尝试。如果您通过代码进行调试,您实际上会看到异步任务在用户从没有可用于打开pdf文件的应用程序时显示的消息框中选择“是”或“否”之前完成。

也无法确定手机上是否有PDF查看应用程序,Windows Phone 8 SDK不存在此功能,但第一方和OEM应用程序似乎可以使用此功能。