开发者

Detect if specified url is an image in Android?

开发者 https://www.devze.com 2023-01-11 04:47 出处:网络
How to detect quickly if a specified URL contains an image in Android? I have link of type http://foo.bar/w23afv so naive approach like checking end 开发者_运维问答of URL string won\'t work here.Che

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

I have link of type http://foo.bar/w23afv so naive approach like checking end 开发者_运维问答of URL string won't work here.


Check if the HTTP Content-Type response header starts with image/.

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

精彩评论

暂无评论...
验证码 换一张
取 消