使用 android webview 下载图像 [英] Download Images using android webview
本文介绍了使用 android webview 下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的 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?
响应头:
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屋!
查看全文