From b4143fbb5e3d4f1df7c8f1e85baa95faf6392a07 Mon Sep 17 00:00:00 2001 From: bilaldhudi <72176087+bilaldhudi@users.noreply.github.com> Date: Wed, 30 Sep 2020 19:43:37 -0700 Subject: [PATCH] Update AdvancedWebView.java download file fix! --- .../android/webview/AdvancedWebView.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/Source/library/src/main/java/im/delight/android/webview/AdvancedWebView.java b/Source/library/src/main/java/im/delight/android/webview/AdvancedWebView.java index 51b8be6..36240b6 100644 --- a/Source/library/src/main/java/im/delight/android/webview/AdvancedWebView.java +++ b/Source/library/src/main/java/im/delight/android/webview/AdvancedWebView.java @@ -1037,18 +1037,34 @@ public void onReachedMaxAppCacheSize(long requiredStorage, long quota, QuotaUpda }); - setDownloadListener(new DownloadListener() { + //Download Handling Start + + super.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.setMimeType(mimeType); + String cookies = CookieManager.getInstance().getCookie(url); + request.addRequestHeader("cookie", cookies); + request.addRequestHeader("User-Agent", userAgent); + request.setDescription("Downloading file...."); + request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType)); + request.allowScanningByMediaScanner(); + request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); + request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType)); + DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); + dm.enqueue(request); + Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_SHORT).show(); + if (mInterstitialAd.isLoaded()) { + mInterstitialAd.show(); + } else { + Log.d("TAG", "The interstitial wasn't loaded yet."); + } + } + }); + //Download Handling End - @Override - public void onDownloadStart(final String url, final String userAgent, final String contentDisposition, final String mimeType, final long contentLength) { - final String suggestedFilename = URLUtil.guessFileName(url, contentDisposition, mimeType); - - if (mListener != null) { - mListener.onDownloadRequested(url, suggestedFilename, mimeType, contentLength, contentDisposition, userAgent); - } - } - - }); } @Override