Reputation: 33
I have an App in which I want to show a PDF file in a WebView. I have tried to do this
webview = (WebView)findViewById(R.id.webview);
progressbar = (ProgressBar) findViewById(R.id.progressbar);
String filename =**"My Firebase PDF Url"**;
webview.loadUrl("https://docs.google.com/gview?embedded=true&url=" + filename);
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
progressbar.setVisibility(View.GONE);
}
});
}
But when I run the App it shows a white screen. Does anybody know what's wrong? I am using a PDF download URL from firebase as "My Firebase PDF Url"
Upvotes: 1
Views: 9584
Reputation: 1
private void downloadPdfFromInternet(String url, final String dirPath, final String fileName) {
PRDownloader.download(
url,
dirPath,
fileName
).build().start(new OnDownloadListener() {
@Override
public void onDownloadComplete() {
File downloadedFile = new File(dirPath, fileName);
progressBar.setVisibility(View.GONE);
showPdfFromFile(downloadedFile);
}
@Override
public void onError(Error error) {
Toast.makeText(mContext,
"Error in downloading file : $error",
Toast.LENGTH_LONG).show();
}
});
PRDownloader.download(
url,
dirPath,
fileName
).build();
}
private void showPdfFromFile(File file) {
pdfView.fromFile(file)
.password(null)
.defaultPage(0)
.enableSwipe(true)
.swipeHorizontal(false)
.enableDoubletap(true)
.load();
}
As Android Decline PDF view from webview, so you can prefer this link
https://github.com/eduxcellence/PDFViewer/find/master
Upvotes: 0
Reputation: 413
String pdf = "https://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
wvPDF.getSettings().setJavaScriptEnabled(true);
wvPDF.loadUrl("https://docs.google.com/gview?embedded=true&url=" + pdf);
wvPDF.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
}
});
Its working for me, Please make sure you have Internet permission and use https://docs.google.com/gview?embedded=true&url=
Upvotes: 7
Reputation: 3273
Try adding these settings to webview,
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setAllowFileAccessFromFileURLs(true);
webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.setWebChromeClient(new WebChromeClient());
Upvotes: 0