Anonymous
Как я могу скачать видео на моем веб -просмотре, просто скачать видео работает, но когда попытаться скачать с pixels.com
Сообщение
Anonymous » 22 сен 2025, 22:32
Вот мой код Android.
Код: Выделить всё
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimeType,
long contentLength) {
String fileName = URLUtil.guessFileName(url, contentDisposition, mimeType);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
String cookies = CookieManager.getInstance().getCookie(url);
if (cookies != null) request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setTitle(fileName);
request.setDescription("Downloading...");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_SHORT).show();
Log.i("DownloadDebug", "Download started for: " + fileName);
}
});
Видео загружалось, но не играет из -за частичной загрузки или отсутствия заголовков
Подробнее здесь:
https://stackoverflow.com/questions/797 ... ing-but-wh
1758569539
Anonymous
Вот мой код Android.[code] webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) { String fileName = URLUtil.guessFileName(url, contentDisposition, mimeType); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setMimeType(mimeType); String cookies = CookieManager.getInstance().getCookie(url); if (cookies != null) request.addRequestHeader("cookie", cookies); request.addRequestHeader("User-Agent", userAgent); request.setTitle(fileName); request.setDescription("Downloading..."); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_SHORT).show(); Log.i("DownloadDebug", "Download started for: " + fileName); } }); [/code] Видео загружалось, но не играет из -за частичной загрузки или отсутствия заголовков Подробнее здесь: [url]https://stackoverflow.com/questions/79771986/how-can-i-download-video-on-my-webview-simple-video-download-is-working-but-wh[/url]