0

An APP is using webview to display a site as if it were an app. I want to make that APP open the reader when a PDF is downloaded. Is this possible?

MaiaVictor
  • 51,090
  • 44
  • 144
  • 286

2 Answers2

1

If you are using a Webview then one way you could handle the PDF is to bind an object that extends WebViewClient to your WebView using the setWebViewClientMethod. The object that extends the WebViewClient will need to override the onLoadResource method.

Inside this method then check your URL for the pdf extension, or for some other attribute of the URL that indicates a PDF, and fire off a new view intent using the PDF URL. This should either offer to open a PDF in an appropriate app. If you want to have a more paranoid fallback you could use Google's PDF renderer by prefixing your URL with http://docs.google.com/viewer?url= then URL encoding the original URL to be opened, for example http://research.google.com/archive/bigtable-osdi06.pdf becomes http://docs.google.com/viewer?url=http%3A%2F%2Fresearch.google.com%2Farchive%2Fbigtable-osdi06.pdf.

marcus.ramsden
  • 2,633
  • 1
  • 22
  • 33
0

Check the content-type of the response and then show the PDF content when appropriate. Have you looked at this post ? How to render PDF in Android It outlines a couple of approaches to open a PDF

Community
  • 1
  • 1
Deepak Bala
  • 11,095
  • 2
  • 38
  • 49
  • 1
    No, I mean. My user will be browsing a site inside a webview. He can randomly decide to download a PDF. When he does it, I want that PDF to be openned. How? – MaiaVictor Oct 19 '12 at 22:06