与web视图下载图像 [英] Downloading images with webview

查看:99
本文介绍了与web视图下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我米显示从web视图移动网站画廊。我如何可以从web视图这些图片?是否存在任何额外设置的WebView?

I m displaying a gallery from a mobile website in webview . How can i download those images from webview ? Are there any extra settings for webview ?

推荐答案

这解决了我的问题。

@覆盖             公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){                 布尔shouldOverride = FALSE;                 //我们只需要处理图像文件的请求,一切的web视图                 //可以处理正常                 如果(url.endsWith(。JPG)){                     shouldOverride = TRUE;                     乌里源= Uri.parse(URL);                     //创建一个新的请求指向MP3网址                     DownloadManager.Request请求=新DownloadManager.Request(源);                     //使用相同的文件名的目标                     文件destinationFile =新的文件(destinationDir,source.getLastPathSegment());                     request.setDestinationUri(Uri.fromFile(destinationFile));                     //添加到经理                     manager.enqueue(要求);                 }                 返回shouldOverride;             }

@Override public boolean shouldOverrideUrlLoading (WebView view, String url) { boolean shouldOverride = false; // We only want to handle requests for image files, everything else the webview // can handle normally if (url.endsWith(".jpg")) { shouldOverride = true; Uri source = Uri.parse(url); // Make a new request pointing to the mp3 url DownloadManager.Request request = new DownloadManager.Request(source); // Use the same file name for the destination File destinationFile = new File (destinationDir, source.getLastPathSegment()); request.setDestinationUri(Uri.fromFile(destinationFile)); // Add it to the manager manager.enqueue(request); } return shouldOverride; }

请一定要添加的权限下载管理器,SD读取,SD写!

make sure to add permissions for download manager, SD read, SD write!

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

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