I have an HTML Web page with a button that triggers a POST request when the user clicks on. When the request is done, the following code is fired:
window.open(fileUrl);
Everything works great in the browser, but when implement that inside of a Webview Component, the new tab doesn't is opened.
FYI: On my Android App, I have set the followings things:
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setSupportMultipleWindows(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
On the AndroidManifest.xml
I have the following permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER"/>
I try too with a setDownloadListener
to catch the download. Another approach was replaced the WebViewClient()
for WebChromeClient()
but the behavior was the same.
Ok I had the same problem working with webviews, I realized that WebViewClient can't load "blob URLs" as Chrome Desktop client does. I solved it using Javascript Interfaces. You can do this by following the steps below and it works fine with minSdkVersion: 17. First, transform the Blob URL data in Base64 string using JS. Second, send this string to a Java Class and finally convert it in an available format, in this case I converted it in a ".pdf" file.
First things first. You have to setup your webview. In my case I'm loading the webpages in a fragment:
Then, create a JavaScriptInterface class. This class contains the script that is going to be executed in our webpage.
Sources:
https://stackoverflow.com/a/41339946/4001198
https://stackoverflow.com/a/11901662/4001198
https://stackoverflow.com/a/19959041/4001198
For who stilll can not download. I edited @Kevin method a little: Replace 'YOUR BLOB URL GOES HERE' with blobUrl