Issue
I am accessing a website which has .pdf documents. If I open that document through a web browser, it starts downloading it. If I open it through webview, nothing happens. What setting should I need to apply to webview to make it start downloading?
I already have this.
wvA.setDownloadListener(new DownloadListener()
{
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType,
long size)
{
Intent viewIntent = new Intent(Intent.ACTION_VIEW);
viewIntent.setDataAndType(Uri.parse(url), mimeType);
try
{
startActivity(viewIntent);
}
catch (ActivityNotFoundException ex)
{
}
}
});
Solution
You should create WebViewClient and set it to your webview. Every time you click a link WebViewClient's shouldOverrideUrlLoading method will be called. Check that url points to pdf file and do what you want. For example, you can view pdf.
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading (WebView view, String url) {
if (url.endsWith(".pdf")) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
// if want to download pdf manually create AsyncTask here
// and download file
return true;
}
return false;
}
});
Answered By - Leonidos
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.