如何检测默认的pdfviewer并在windows phone中打开PDF [英] How to detect default pdfviewer and open PDF in windows phone

查看:36
本文介绍了如何检测默认的pdfviewer并在windows phone中打开PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to working on download and open pdf file in windows phone 8. Where the code is successfully working when any pdf viewer (Adobe, MS PDF Reader etc.) presents on phone.

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查看器时,它正在执行相同的成功代码块,即

But when there is no pdf viewer present on the phone, it is executing the same success code block i.e.

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

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

and open windows phone system message box, Can is it possible to detect it before system identify so that I will show my own/custom created message box here? Because on no click of windows phone system message box I want user to redirect on some other page.

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

Is there any way to detect pdf viewer application present or not before LaunchFileAsync(filepath) method?

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

Can anyone please suggest me way how I will get solution.

谁能指导我如何使用LaunchFileAsync的以下方法?在 MSDN 中,它声明此方法最低支持电话 ::Windows Phone 8.1.Windows phone 8 有类似的吗?

Can anyone please guide me how to use below methode of LaunchFileAsync? In MSDN its stated that this method Minimum supported phone :: Windows Phone 8.1. Is there any similar for Windows phone 8?

LaunchFileAsync(IStorageFile, LauncherOptions)

推荐答案

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

Unfortunately the 'true' return value from LaunchFileAsync simply means that the attempt to launch this file was performed successfully. If you debug through your code you'll actually see that the asynchronous task completes before the user selects 'Yes' or 'No' from the message box that displays when there is no app available to open a pdf file.

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

There is also no way to determine if a PDF viewing app is available on the phone, this capability does not exist for the Windows Phone 8 SDK, although 1st party and OEM apps seem to have this feature available.

这篇关于如何检测默认的pdfviewer并在windows phone中打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆