Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download Images using android webview

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

<a href="../Temp/Images/def.jpg" download="">Download</div></a>

Which works fine on a chrome browser but does not work in my webview app. I already activated several permissions.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

But still the link does not react. How can I trigger a download?

EDIT:

Response Headers:

Cache-Control:private
Connection:Close
Content-Disposition:attachment; filename=IMG_20141004_171308.jpg
Content-Length:3039432
Content-Type:image/jpeg
Date:Wed, 15 Oct 2014 12:35:57 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:4.0
like image 557
zanzoken Avatar asked Nov 27 '25 21:11

zanzoken


1 Answers

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

    }
});
like image 53
Confuse Avatar answered Nov 29 '25 15:11

Confuse