在Android中打开pdf文件的限制 [英] Limitations on opening pdf file in Android

查看:530
本文介绍了在Android中打开pdf文件的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的Android应用程序中打开一些pdf文件.我正在使用一个Intent来做到这一点:

I am trying to opening some pdf from my Android application. I am using an Intent for doing that:

Intent intent = new Intent();
intent.setDataAndType(Uri.parse(url), "application/pdf");
startActivity(intent);

此代码对于某些pdf效果很好,但是当我尝试打开其他pdf时却失败.

This code works well for some pdf but it fails when I try to open others.

这是Android向我显示的消息:

This is the message that Android is showing to me:

文件有问题.

There is a problem with the file.

我必须提到的是,使用一个Crystal Report模板创建了无问题打开的pdf,而使用另一个Crystal Report模板创建了失败的pdf.

I have to mention that the pdf that are being opened without problems are created with one Crystal Report template and the pdfs that are failing are created with another one.

相反,如果我打开在我的浏览器(在我的计算机上)上失败的pdf的url,打开它并不会给我任何错误,所以我想也许Android上有一些限制与一些pdf到另一个(在Crystal Report模板上),但我看不到.

As opposed, if I open the url of the pdfs that are failing on my browser (on my computer), it does not give to me any error opening them so I guess that maybe there is some limitation on Android that differs from some pdf to another (on Crystal Report template) but I cannot see it.

在Android上打开pdf文件存在哪些限制? (大小,不允许使用Crystal Report的某些参数,等等.)

What limitations exist on opening a pdf file on Android? (Size, some parameters of Crystal Report that are not allowed, etc...)

我已经放弃了可能的大小限制,因为出现问题的pdf文件比没有出现任何错误的文件小.

I have discarded that it could be a size limitation because the pdf files that are giving problems are smaller than the files that do not give any error.

证明我已经完成:

  • 在浏览器中打开错误的PDF ~~>确定
  • 在手机上下载错误的PDF并打开它~~>确定
  • 在APP上打开错误的PDF ~~> 错误
  • 在PDF崩溃的公司的APP上打开好的PDF ~~>可以
  • Opening wrong PDFs on browser ~~> OK
  • Downloading wrong PDF on mobile phone and open it ~~> OK
  • Opening wrong PDFs on APP ~~> Error
  • Opening good PDF on APP of the company that PDFs crash ~~> OK

编辑

我注意到我使用的是http://协议,但是PDF使用的是https://协议,因此我在Uri.parse方法上进行了更改.

I have noticed that I was using http:// protocol but the PDF is on a https:// protocol, so I have changed it on Uri.parse method.

进行此更改时,应用程序崩溃了,日志上显示了一个错误:

When I made this change, the app crashed and an error was shown on the log:

android.content.ActivityNotFoundException:未找到用于处理Intent的活动

android.content.ActivityNotFoundException: No Activity found to handle Intent

此外,我注意到没有给我任何错误的PDF包含在http://协议而不是https://的url中,所以我猜想https://协议可能是问题所在.

Also, I have noticed that the PDFs that does not give to me any error, are in an url with http:// protocol instead of https:// so I guess that https:// protocol can be the problem.

我只能在Intent上打开http://请求吗?

Am I only able to open http:// request on an Intent?

推荐答案

我找到了一种解决方法,可以在我的Android应用程序上查看我的PDF(但在该应用程序显示后不允许我下载它).如果我使用Google文档打开PDF,则可以使用我的Intent打开它.

I found a workaround to view my PDF on my Android application (but does not allow me to download it after show on the application). If I open my PDF using Google Docs I can open it with my Intent.

这是我必须在网址之前添加的内容:

This is what I had to add before my url:

https://docs.google.com/gview?embedded=true&url=

因此最终的网址将如下所示:

so the final url will be like:

https://docs.google.com/gview?embedded=true&url=https://myUrl.pdf

这是我现在正在使用的全部代码:

Here is the whole code I am using right now:

String url= "https://docs.google.com/gview?embedded=true&url=https://url.pdf";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);

但这还不够,因为我想打开它而不需要使用第三方应用程序.另外,使用Google文档打开PDF的速度很慢,我不得不等待太多时间才能最终打开PDF.

But it is still not enough, because I would like to open it without need of using a third party application. Also, opening PDF with Google Docs is slow and I have to wait too much until the PDF is finally opened.

如果有人知道如何使用本机Android打开它,请告诉我.

If anyone knows how to open it with native Android please let me know.

如果我不使用Google文档打开它会怎样?

Android使用相同的代码,但仅使用我的网址,而不是添加的Google文档网址,因此我可以在以下两个应用程序之间进行选择:Adobe Acrobat Reader和Google Chrome.

With the same code, but just using my url, instead the added Google Docs url, Android let me choose between two applications: Adobe Acrobat Reader and Google Chrome.

  • 如果我使用Google Chrome浏览器打开它,则会下载PDF,但不会自动打开.

  • If I open it with Google Chrome it download the PDF but it is not opened automatically.

如果我使用Adobe Acrobat Reader将其打开,则会出现以下错误:

If I open it with Adobe Acrobat Reader, it gives to me the following error:

无法显示PDF(无法打开)

The PDF cannot be shown (it cannot be opened)

这篇关于在Android中打开pdf文件的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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