Android WebView下载不适用于HTML文件

时间:2019-05-22 09:14:34

标签: android android-webview

我有一个html文件,其中包含以下内容,这些内容将允许下载图片,我已经从浏览器进行了测试,下载工作正常。

<a href="logo.png" id="downlink"  style="display:inline-block;" download> download</a>

在Android Java中,我可以下载以下代码

          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();

                }
            });

但是,当我单击下载链接时,没有任何反应。 onDownloadStart方法不会被调用。可能是什么问题。

0 个答案:

没有答案