Download Images using android webview

后端 未结 2 1341
醉梦人生
醉梦人生 2020-12-05 22:09

I want to download images inside my webview. I used a link tag like this

Download
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 22:54

    Try adding download listener -

    mWebView.setDownloadListener(new DownloadListener() {
    
        public void onDownloadStart(String url, String userAgent,
            String contentDisposition, String mimetype,
                                       long contentLength) {
    
                Request request = new Request(Uri.parse(url));
                request.allowScanningByMediaScanner();
    
                    request.setNotificationVisibility(
                    DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    
                    request.setDestinationInExternalPublicDir(
                    Environment.DIRECTORY_DOWNLOADS,    //Download folder
                    "download");                        //Name of file
    
    
                    DownloadManager dm = (DownloadManager) getSystemService(
                    DOWNLOAD_SERVICE);
    
                    dm.enqueue(request);  
    
        }
    });
    

提交回复
热议问题