Reputation: 95
I am working on an Android application that opens urls its content is HTML or Pdf ... I used this way to open it
WebView webView = (WebView) mContentView.findViewById(R.id.web_view);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
// This is the url that may be .html or .pdf
String url = "https://uva.onlinejudge.org/external/1/119.html";
//String url = "https://uva.onlinejudge.org/external/11/1124.html";
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if (progress >= 100) {
setContentShown(true);
}
}
});
webView.loadUrl(url);
the first url opens normally in the webview, but the second url doesn't show anything in the webview .. and If I try to open it on the browser it redirects me to this url [https://uva.onlinejudge.org/external/11/p1124.pdf] and open normally.
Any help will be appreciated.
Upvotes: 1
Views: 1743
Reputation: 64
Set a download listener to your webview. Inside the listener, you can choose to download the PDF by overriding its methods.
webView.setDownloadListener(new (DownloadListener listener) { // is it a pdf? });
Upvotes: 1