Issue and Testing
By default, Android’s browsers (includes default browser, Chrome and Firefox) do not support open PDF files inside browser. This also applies to WebView we are using inside app.
This brings up a issue that in our app, when user click Windows Sticker, the pop up windows asks user to choose a browsers to open the link. However, no matter which browsers user use, the file will be downloaded, instead of opened.
I have tested these issue by:
- Open windows sticker’s link inside our app.
- Open windows sticker’s link from email or notes.
- Open normal http links point to a pdf file inside our app
- Open normal http link point to a pdf file from email or notes.
All test result shows that for now, we can not achieve the same behavior that we want at beginning, that is, open pdf inside a external browser.
There are couple of work around about this problem.
Using PDF reader app to open the link
This solution comes to be the most intuitive one. However there are two risks we need to consider:
- The link of Windows Sticker is not a direct link to the pdf file, but a redirection. We need to manually override this behavior to let it open by another app.
- The user is very possible doesn’t have a PDF reader app install on the phone!
Using Google Docs embed inside Webview.
Google has provide a google docs web version. Basicly, you just assemble a new url points to the Google’s services, then the Google Docs will open the file inside google drive. This approach also has some risks:
- Google constantly changing their services configuration. The embed code has changed in the past and is very likely be changed in the future.
- Using this services require user already installed Google Drive and on some phone, asking user to be registered their phone with Google Services.
- During testing, this services not coop very well with WebView, though it could display the pdf, the navigation and render speed is very limited.
Intergated PDF render and viewer function inside our app.
This could be the most stable and once for all solution. We could write in our own pdf viewer function inside our app. However, this approach also has some drawback.
- PDF standard are constantly update and changes. We need to keep maintenance our library if we decide to write our own.
- There possibly will be some performance issue with our app, though very unlikely, but still a risk to consider at start.