ダウンロードリスナーは決して呼び出さず、私も動的ダウンロードリンクを取得していません。Webviewダウンロードリスナーは決してコールしません。
ボタンをクリックしながら、私はダウンロードボタンをクリックしながら、それが正常に直接Chromeブラウザ経由でドキュメントをダウンロードします、ドキュメントのダウンロードリンクを生成しますが、Web表示を使用することはありませんが、ダウンロードボタンが含まれている1つのウェブサイトを持っています自動的にドキュメントをダウンロードし、リスナーの呼び出しも受け付けません。
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