Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "application/pdf");

Thanks

like image 703
cottonBallPaws Avatar asked Jan 12 '11 02:01

cottonBallPaws


People also ask

How do I open a URL with intent?

To open a URL/website you do the following: String url = "http://www.example.com"; Intent i = new Intent(Intent. ACTION_VIEW); i.

How can I view a PDF online without downloading it?

Easy to use PDF viewer Fed up with having to download additional software to view a PDF file? Use DocFly to view PDF online so you can quickly read and edit your files. No software downloads required.

How can I open PDF in Android programmatically?

Opening a PDF file in Android using WebView All you need to do is just put WebView in your layout and load the desired URL by using the webView. loadUrl() function. Now, run the application on your mobile phone and the PDF will be displayed on the screen.


1 Answers

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.

like image 149
matheeeny Avatar answered Sep 21 '22 14:09

matheeeny