检测指定的网址是否为Android中的图片?

pix*_*xel 8 url android image http

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

我有类型的链接http://foo.bar/w23afv所以天真的方法,如检查URL字符串的结束将无法在这里工作.

Bal*_*usC 31

检查HTTP Content-Type响应头是否以image/.

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