1
をダウンロードしませんが、何もダウンロードしません。ファイルのダウンロードを開始すると、ファイルはキューリストに置かれ、ダウンロードは開始されません。これは私のコードです:DownloadManagerはダウンロードマネージャを使用して
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, final String contentDisposition, final 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) activity.getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(activity.getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
}
});
私はdebbugの場合、すべての値が正しいようです。この正確なコードはAndroid 6.0で動作しますが、Android 7.0でそれを試してみると動作しません。
助けが必要ですか?
ありがとうございます!
はい、私はすべての許可を求めます。マニフェストでuses-permissionも追加しました。 –