Wie kann ich Videos in meinem Webview herunterladen? Ein einfacher Video -Download funktioniert, aber wenn ich versuche,Android

Forum für diejenigen, die für Android programmieren
Anonymous
 Wie kann ich Videos in meinem Webview herunterladen? Ein einfacher Video -Download funktioniert, aber wenn ich versuche,

Post by Anonymous »

Hier ist mein Android-Code, in dem er Bilder , document , Videos, aber einige Plattformen wie Pixel ihre Videos auf Teilen oder Streams zum Herunterladen
herunterladen kann.

Code: Select all

 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);
}
});
Video wurde heruntergeladen, aber nicht spielbar aufgrund von teilweise Download oder fehlenden Headern

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post