什么意图将开辟从URL一个PDF文件?开辟、意图、文件、URL

2023-09-03 21:06:56 作者:玩膩丶ceiling

我想创建,将网页(网址)在PDF阅读器上打开PDF文件的意图。它似乎只工作,如果该文件是本地的。

I am trying to create an intent that would open a pdf file on the web (a url) in a pdf reader. It seems to only work if the file is local.

我知道这是要取决于是否有任何已安装的应用程序可以处理的URL,但因为我已经安装了几个PDF阅读器(有些人声称他们可以在网络上阅读PDF文件),其中没有一个是响应我想看看是否有什么错我的意图。

I know this is going to depend on whether or not any of the installed apps can handle urls, but since I have several pdf readers installed (some of them claim they can read pdfs on the web) and none of them are responding I wanted to see if there was something wrong with my intent.

下面是我目前使用的:

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

感谢

推荐答案

创建一个URL来使用谷歌文档查看器的PDF格式。这结束了加载速度更快,因为他们不必再下载该文件的全部内容,才能显示出来。

Build a url to the pdf using google docs viewer. This ends up loading much faster as they don't have to download the file in its entirety before you can display it.

private static final String googleDocsUrl = "http://docs.google.com/viewer?url=";

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(googleDocsUrl + url), "text/html");

我们最近做了,除了我们用我们自己的活动与嵌入式web视图来显示PDF格式,而不是去到浏览器类似的东西。

We recently did something similar except we used our own activity with an embedded webview to display the pdf rather than going to the browser.