开发者

WebView troubling with loading images

I'm developing simple app for Android that display images in WebView.

While coding i get problem with load data in WebView. When i try to load some data like:

String data = "<html><body><img src="http://xxxxxxxxxxx"/></body></html>";

WebView.loadData(data, "text/html", "utf-8");

The image can't be loaded because the link in src="" is redericting me to another page that contains not only image but full web page.

The example is:

WebView troubling with loading images

(source: kwejk.pl)

When i try to load this image it redirect me to that page

It's even working l开发者_StackOverflowike that in Desktop Browser, Phone etc.

Is there any solution to disable redirecting to another page when loading image??

Please help.


They do this on purpose so that other users don't link to their content directly.

The answer is: Depends how they do it. In this case it seems that they use cookies. The first time you visit the link you get redirected, the second time is shows the picture directly.

So, the workaround would be to do a HttpClient GET, handle the redirect and then remember the cookies. Then use those cookies in a subsequent WebView calls to this site.

UPDATE: they seem to use per-page cookies, which means that you would need to pre-fetch the cookie for every image.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜