开发者

What intent would open a pdf from a url? [duplicate]

This question already has answers here: How to render PDF in Android (6 answers) Closed 9 years ago.

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.

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.

Here is what I am currently using:

Intent intent = new Intent(I开发者_JAVA百科ntent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "application/pdf");

Thanks


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");

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.


You can simply load the following URL in the Webview

webView.loadUrl("https://drive.google.com/viewerng/viewer?embedded=true&url=" + url);

Google docs will take care to load the PDF URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜