I have html file with following content which will allow an image to download, I have tested it from browser and the download working fine.
<a href="logo.png" id="downlink" style="display:inline-block;" download> download</a>
And in Android Java I have the following code to download
myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
myWebView.getSettings().setAllowFileAccess(true);
myWebView.getSettings().setAppCacheEnabled(false);
myWebView.clearCache(true);
myWebView.loadUrl("http://192.168.1.3:8075/DB_1/html/LiveMain.html");
myWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype, long contentLength) {
if (url.startsWith("data:")&&url.contains("/")&&url.contains(";")) { //when url is base64 encoded data
String path = createAndSaveFileFromBase64Url(url);
return;
}
Toast.makeText(getApplicationContext(),"Failed to download snap", Toast.LENGTH_LONG).show();
}
});
But when I click the download link nothing happens. The onDownloadStart
method not get called. What could be the issue.