在Windows Phone 8推出的PDF阅读器 [英] Launching PDF reader on windows phone 8

查看:122
本文介绍了在Windows Phone 8推出的PDF阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图推出PDF阅读器与下面的代码,但它不工作。 ?有人可以帮我。

I'm trying to launch pdf reader with the code below but it does not work. Can somebody help me?

    private async Task<StorageFile> WriteData(string fileName, byte[] data)
    {
        StorageFolder folder = ApplicationData.Current.LocalFolder;

        StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

        using (Stream s = await file.OpenStreamForWriteAsync())
        {
            await s.WriteAsync(data, 0, data.Length);
            s.Close();
        }

        return file;
    }

    private async Task<bool> OpenPdf(StorageFile file) 
    {

        var uri = new Uri(file.Path, UriKind.RelativeOrAbsolute);
        bool result = await Windows.System.Launcher.LaunchUriAsync(uri);

        return result;
    }

    private async void FetchPdf() {
         // Fetch pdf bytes to network
         //....
         StorageFile file = await WriteData("test.pdf", data);

         if (file != null) {
            bool result = await OpenPdf(file);     
            if (result)
              Debug.WriteLine("Success");
            else 
              Debug.WriteLine("Cannot open pdf file.");
         }
    }



结果始终是假的,因此发射不会出现。

result is always false and so launcher is not presented.

我用LaunchUriAsync因为LaunchFileAsync不是Windows Phone上实现的。

I used LaunchUriAsync because LaunchFileAsync is not implemented on Windows Phone.

推荐答案

LaunchUriAsync 不支持在Windows Phone 8%的< A HREF =htt​​p://msdn.microsoft.com/en-us/library/windows/apps/hh701484.aspx相对=nofollow>文档。这将引发称为异常

LaunchUriAsync isn't supported on Windows Phone 8 per the documentation. It throws an exception if called

您可以使用 Windows.System.Launcher.LaunchFileAsync 推出 StorageFile

这代码的工作,例如(assming有一个名为metro.pdf文件项目,以生成操作设置为内容复制到输出目录设置为复制如果较新的)。

This code works for example (assming there's a file called "metro.pdf" in the project, with the Build Action set to Content, with Copy to Output Directory set to Copy if Newer).

var installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
var assets = await installedLocation.GetFolderAsync("Assets");
var pdf = await assets.GetFileAsync("metro.pdf");
Windows.System.Launcher.LaunchFileAsync(pdf);

这篇关于在Windows Phone 8推出的PDF阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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