kralco626
kralco626

Reputation: 8654

Open pdf documents in browser on Android 4+

I have seen several of these question from 1-2 years ago about Android pre-4.0. I want to ask this again for Android 4+.

I have a galaxy s3 running 4.3 and when I click on a pdf link it downloads the document rather than opening it in the browser.

I am building a website and it will have links to pdf documents. The desired behavior when one of my users clicks on the pdf link on their Android device is for the pdf document to just open like it would on a desktop browser.

Is there anything I can do to achieve this functionality, or does Android still not support this?

I cannot control the device that a user is using, so I'm looking for a solution that would achieve this functionality in as many cases as possible.

Upvotes: 0

Views: 851

Answers (2)

CommonsWare
CommonsWare

Reputation: 1007584

it downloads the document rather than opening it in the browser.

"it" is a Web browser. There are many Web browsers for Android. A Web browser can do whatever it wants when the user clicks on a link to a PDF file.

The desired behavior when one of my users clicks on the pdf link on their Android device is for the pdf document to just open like it would on a desktop browser.

That is not the behavior of all desktop browsers, particularly depending upon user configuration (e.g., browser extensions). A desktop Web browser, like a mobile Web browser, is welcome to do whatever it wants when the user clicks on a link to a PDF file.

does Android still not support this?

Android is an OS. Android neither supports nor does not support this. Web browser applications will or will not support what you want.

I cannot control the device that a user is using, so I'm looking for a solution that would achieve this functionality in as many cases as possible.

You are welcome to test a variety of Android Web browsers, see if there are any that behave the way you like, and suggest to your users that you would prefer that they use those browsers. Your users, in turn, are welcome to honor or ignore your request.

Or, as Chris M points out, you are welcome to not show a PDF at all, but rather redirect the user to some URL that processes the PDF and renders it in some other way.

Upvotes: 0

GrouchyPanda
GrouchyPanda

Reputation: 1084

The stock browser does not support native viewing of PDFs. You can however redirect the link to google docs and view internally that way. To do this, launch your implicit view intent, as I suspect you are already doing, but prepend the URI with "https://docs.google.com/gview?url=" and Google will take care of the rest

Alternately, there are a few libraries that you will see linked around SO, but from what I saw while researching, most are proprietary and cost and even then they might not work 100%. Google docs is free and works as often as Google does, which given that this is their platform you have to imagine they make certain their service works close to 100% of the time.

Upvotes: 1

Related Questions