Pawan
Pawan

Reputation: 73

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? If not, is there a way to check after the page has loaded in the webview?

I know that I could download every page using HttpURLConnection, but I'm trying to avoid that approach.

Upvotes: 0

Views: 649

Answers (1)

Wand Maker
Wand Maker

Reputation: 18762

Check Response HTTP Header Content-Type. It will be one of the image types. For Example, if I open the URL you have provided in Browser, will see Content-Type as show below

Content-Type:image/jpeg

You can use HttpHead method to fetch just the headers

enter image description here

Upvotes: 1

Related Questions