无法在WebView中下载视频文件

时间:2018-04-25 11:50:22

标签: android webview android-download-manager

当我点击WebView中的链接时,视频下载开始但视频格式未知,因为Android没有播放下载的视频文件。 此外,当我从chrome中的同一链接下载视频时,视频下载的格式正确,并且android能够播放视频文件。

        WebView webview = (WebView) findViewById(R.id.web1);
    webview.setWebViewClient(new WebViewClient());
    webview.loadUrl("my url");

    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.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Game of thrones ");
            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            dm.enqueue(request);
            Toast.makeText(getApplicationContext(), "Downloading File", //To notify the Client that the file is being downloaded
                    Toast.LENGTH_LONG).show();

        }
    });

0 个答案:

没有答案