0

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.

CodeDezk
  • 1,230
  • 1
  • 12
  • 40
  • do you already declare in manifest the permission like WRITE_EXTERNAL_STORAGE? – No Name May 22 '19 at 09:18
  • Yes I have the following in manifest `` – CodeDezk May 22 '19 at 09:21
  • did you try in a different way like using shouldOverrideUrlLoading instead onDownloadStart – No Name May 22 '19 at 10:04
  • Did you read this: https://forums.xamarin.com/discussion/19728/why-does-the-ondownloadstart-method-from-downloadlistener-never-gets-called https://stackoverflow.com/questions/9722111/how-do-i-use-downloadlistener https://stackoverflow.com/questions/26379174/download-images-using-android-webview – Steven May 23 '19 at 02:11
  • Possible duplicate of [Download Images using android webview](https://stackoverflow.com/questions/26379174/download-images-using-android-webview) – Steven May 23 '19 at 02:12

0 Answers0