Android : How to open a PDF from WebView in Android

on Thursday, August 14, 2014


I'm writing an application that makes heavy use of some JavaScript inside of WebView. I have a function inside of a String that allows me to download a PDF that works fine on my desktop enviornment as long as my popup blocker is disabled.


So I disabled the popup blocker as described in some other posts that I've found then loaded my HTML and JS using the following code.



String js = "....";
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setAllowFileAccess(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setSupportMultipleWindows(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.loadDataWithBaseURL("http://...", js, "text/html", "UTF-8", null);


Everything works fine except for my PDF. I'd expect to be given a new window having allowed multiple windows and JavaScriptCanOpenWindowAutomatically.


Is there some other WebView setting I need to change to allow PDF's to be opened/viewed/downloaded?


Edit: It should be noted that I'm relying, for now, on whatever reader the user has on the system to take over the viewing of the PDF unless WebView has a built in way of viewing them.


0 comments:

Post a Comment