检测是否指定的URL在Android中的图像? [英] Detect if specified url is an image in Android?

查看:185
本文介绍了检测是否指定的URL在Android中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何快速检测是否指定的URL包含在Android中的图像?

How to detect quickly if a specified URL contains an image in Android?

我有类型的链接 http://foo.bar/w23afv 如检查URL字符串的结尾不会在这里工作这么幼稚的做法。

I have link of type http://foo.bar/w23afv so naive approach like checking end of URL string won't work here.

推荐答案

检查HTTP的 内容类型 响应头以图像/

URLConnection connection = new URL("http://foo.bar/w23afv").openConnection();
String contentType = connection.getHeaderField("Content-Type");
boolean image = contentType.startsWith("image/");

这篇关于检测是否指定的URL在Android中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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