采用了android的WebView下载图片 [英] Download Images using android webview

查看:695
本文介绍了采用了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>

在哪些Chrome浏览器工作正常,但在我的WebView应用程序不起作用。我已经激活几个权限。

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?

编辑:

响应头:

缓存控制:私人
连接:关闭
内容处置:附件;文件名= IMG_20141004_171308.jpg
内容长度:3039432
内容类型:图像/ JPEG
日期:周三,二零一四年十月一十五日12时35分57秒GMT
服务器:ASP.NET开发服务器/ 10.0.0.0
的X ASPNET-版本:4.0.30319
的X AspNetMvc-版本:4.0

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

推荐答案

尝试添加下载监听器 -

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

    }
});

这篇关于采用了android的WebView下载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆