0

I convert my website into an android webview app. Everything is working fine but when I am trying to download any file from my website the file is downloading in HTML format. But the files were downloading in correct format when I tried to download from a pc or mobile browser.

webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            DownloadManager.Request myRequest = new DownloadManager.Request(Uri.parse(url));
            myRequest.allowScanningByMediaScanner();
            myRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

            DownloadManager myManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            Objects.requireNonNull(myManager).enqueue(myRequest);
            Toast.makeText(MainActivity.this,"Download Started....", Toast.LENGTH_SHORT).show();
        }
    }
Sajeeb Shahriar
  • 102
  • 1
  • 8
  • These answers may help you https://stackoverflow.com/questions/10069050/download-file-inside-webview and https://stackoverflow.com/questions/33434532/android-webview-download-files-like-browsers-do/33501835 – Bek Mar 22 '19 at 07:03
  • It works, Thank you very much – Sajeeb Shahriar Mar 22 '19 at 07:36

0 Answers0