[英]In Android, how do I check if the URL being loaded in a webview is an image?
Checking the extension of the file works in most cases, but not for all. 在大多数情况下,检查文件扩展名是可行的,但并非全部。 Consider the following link:
考虑以下链接:
http://t0.gstatic.com/images?q=tbn:ANd9GcTqqcX4SsdwgithvRcjQl_W3Hj-eIc_12FvdeGS2sO31uZ0F1HHqcdRKNo
Can I check from the URL if it is a link to an image? 我可以从URL中检查它是否是图像的链接吗? If not, is there a way to check after the page has loaded in the webview?
如果没有,是否有一种方法可以将页面加载到Webview中后进行检查?
I know that I could download every page using HttpURLConnection, but I'm trying to avoid that approach. 我知道我可以使用HttpURLConnection下载每个页面,但是我试图避免这种方法。
Check Response HTTP Header Content-Type
. 检查响应HTTP标头
Content-Type
。 It will be one of the image
types. 这将是
image
类型之一。 For Example, if I open the URL you have provided in Browser, will see Content-Type
as show below 例如,如果我打开浏览器中提供的URL,将看到
Content-Type
,如下所示
Content-Type:image/jpeg
You can use HttpHead
method to fetch just the headers 您可以使用
HttpHead
方法仅获取标头
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.