0
下载监听器永远不会调用,我也没有获得动态下载链接。Webview下载监听器永远不会调用
我有一个网站,包含下载键,同时点击按钮,它生成下载链接的文档,当我点击下载按钮,它成功地将通过铬直接浏览器下载文件,但使用Web浏览它不是自动下载文件以及不接听任何听众的电话。
webView.loadUrl(WEBSITELINK);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Log.v("Url:","shouldOverrideUrlLoading");
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// download link generates dynamically by clicking on button
webView.loadUrl("javascript:(function(){document.getElementById('download').click();})()");
}
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
//------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
}
});
有什么办法可以强制完全调用监听器吗? – Nik