0
我在android webview中打開一個網頁。填寫網頁上的信息後,會出現一個用於下載文件的按鈕。但該文件沒有下載。我對將哪個url傳遞給下載任務感到困惑。叮噹響按鈕應該下載一個pdf文件。但它什麼也沒做Webview下載文件
mWebView.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.allowScanningByMediaScanner();
request.setMimeType(mimetype);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,URLUtil.guessFileName(url, contentDisposition, mimetype));
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager dm = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
您是否設置了正確的權限?分享您的清單文件並將記錄器放入您的代碼並共享日誌 –
您是否設置了正確的權限?分享您的清單文件並將記錄器放入您的代碼並共享日誌 –
<使用權限android:name =「android.permission.INTERNET」/> <使用權限android:name =「android.permission.ACCESS_NETWORK_STATE」/> uses-permission> –