Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Download NTLM Authentication Protected Files

I have tried with downloading with DownloadManager apis of Android but failed to succeed.

Here is my sample code which returns me Download UnSuccessful.

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);
        }
    });
like image 783
Akash Avatar asked Nov 15 '22 19:11

Akash


1 Answers

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);
        });
like image 62
Htin Linn Zaw Avatar answered Dec 23 '22 17:12

Htin Linn Zaw