Android的开放PDF格式不工作 [英] Android opening pdf isn't working

查看:175
本文介绍了Android的开放PDF格式不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力,现在得到这个工作了一段时间。我在这里如何从Android打开PDF文件见过的其他问题,而一般的共识是code,我有以下。我缺少的东西吗?

I've been trying to get this working for some time now. I've seen the other questions here about how to open pdfs from Android, and the general consensus is the code that I have below. Am I missing something?

    try
    {
        Uri path = Uri.parse("android.resource://com.TeamGLaDOS.DayTradeSim/" + R.raw.teamdoc);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(path, "application/pdf");
        this.startActivity(intent);
    }
    catch(ActivityNotFoundException e)
    {
        Toast.makeText(this, "No Application Available to view PDF",     Toast.LENGTH_SHORT).show();
    }

编辑:它总是抛出ActivityNotFoundException并显示吐司。

It always throws the ActivityNotFoundException and shows the Toast.

异常消息是这样的:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.TeamGLaDOS.DayTradeSim/2130968576 typ=application/pdf }

编辑2:我安装(Aldiko)PDF应用程序,我已经使用其他应用程序之前在Aldiko推出的PDF文件。

Edit 2: I have a pdf application installed (Aldiko) and I've used other apps to launch pdfs in Aldiko before.

推荐答案

您URI构造适当地ID访问原始资源,但是,这并不意味着所有的PDF阅读器将解决与<$ C $意图C> android.resource:// 数据URI方案。
这一定程度上取决于安装在用户设备上的PDF阅读器应用程序的执行,但很多检查不仅仅是在你的意图将mimeType多。 Adobe Reader中,例如,将解决与一个文件的任何意图:// URI,内容:// URI或者没有URI在所有的(只是将mimeType),但它不会解决一个URI直接在资源指指点点。

Your URI is constructed appropriately to access a raw resource by ID, but that doesn't mean that all PDF readers will resolve an intent with an android.resource:// data URI scheme. It depends somewhat on the implementation of the PDF Reader application installed on the user's device, but many check more than just the mimeType set in your intent. Adobe Reader, for example, will resolve for any Intent with a file:// URI, content:// URI, or no URI at all (just the mimeType), but it will not resolve for a URI pointing directly at a resource.

要尽可能通用,你应该先复制要读出你的资产/资源,并到文件系统(内部或外部存储的PDF文件,并​​没有区别,只要创建外部可读的文件)。然后用URI传递的意图,该文件实例,你应该有整体更好的运气。

To be as universal as possible, you should first copy any PDF file you want to read out of your assets/resources and onto the file system (internal or external storage, makes no difference as long as the file is created externally readable). Then pass the intent with a URI to the file instance, and you should have much better luck overall.

一个快速测试显示,Aldiko只响应一个意图与文件:// URI和应用程序/ PDFmime类型,并没有其他的选择,即使是ADOBE READER决心......所以有你的赢家。

A quick test showed that Aldiko ONLY responds to an Intent with a file:// URI and "application/pdf" mimeType, and none of the other options that even Adobe Reader resolved to...so there's your winner.

心连心

这篇关于Android的开放PDF格式不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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