5

我曾尝试使用 Android 的 DownloadManager api 进行下载,但未能成功。

这是我的示例代码,它返回我下载不成功。

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.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
            DownloadManager dm = (DownloadManager) MainActivity.this.getSystemService(MainActivity.this.DOWNLOAD_SERVICE);
            dm.enqueue(request);
        }
    });
4

2 回答 2

1

As for me, Your code is working well. Here is my code and no changes happen. Since I wan t to help you, you should post your download server IP if you can. So I can test your server.

My server is apache web server and Since it is one of our production server, forgive me as I cannot express my server. May be the problem is your web server configuration or credentials or security certificates.

        WebView webview = new WebView(FileDownloadActivity.this);
        webview.loadUrl("http://167.172.70.x/xxxxxxxxx-version-1.9.apk");

        webview.setDownloadListener((url, userAgent, contentDisposition, mimeType, contentLength) ->
        {
            String fileName = URLUtil.guessFileName(url, contentDisposition, mimeType);
            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
            DownloadManager downloadmanager = (DownloadManager) getApplicationContext().getSystemService(FileDownloadActivity.this.DOWNLOAD_SERVICE);
            downloadmanager.enqueue(request);
        });
于 2020-01-10T07:30:48.143 回答
-1

转到 IIS 管理器并在创建新网站时

在身份验证 -> 选择 windows 身份验证 -> 提供者 -> 删除协商并仅保留 NTLM 。

并参考以下链接下载 NTLM 保护文件。 https://github.com/square/okhttp/issues/206

于 2020-01-03T11:18:05.220 回答