I have a issue in loading images in the webview. the normal images in the src tags are loading perfectly .but there is an custum image tag.
<img class=\"lazy lazy-hidden aligncenter size-full wp-image-40307\" src=\"data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=\" data-lazy-type=\"image\" data-lazy-src=\"http://www.hdwallpapersimages.com/wp-content/uploads/2014/01/Winter-Tiger-Wild-Cat-Images.jpg\" alt=\"yoyo\" width=\"600\" height=\"400\" title=\"Title\" />
i am loding the data in the webview like below
news_deatilsWv
.loadDataWithBaseURL(null, dataString, "text/html", "UTF-8", null)
dataString contain the the entire html data which i displayed, only this custom image portion is not loading.i search the web and found it is related t the base 64 encoding but cant find how to fix this. can any one suggest an idea or solution to fix this problem.
Related
I've got a question related to the showing HTML data inside WebView.
I have quite big HTML string with some images with src in base64 format. I'm reading this data from file. File reading is quite fast and I have no issues with this.
When it's only one image inside HTML - it works fine. But when at least a couple - it's lagging a lot. (It's loading about 30-35 seconds)
I tried to speed up it but no result.
This is the way I load HTML string.
WebView.loadDataWithBaseURL("file:///", StringEscapeUtils.unescapeHtml4(hmtl), "text/html", "UTF-8", null);
I use this function with base URL "file:///" because I'm going through the links(local) inside this file. So I guess it's obligatory to use this kind of function.
Can anyone help me with a solution?
I use webview to load local html data like this
webview.loadDataWithBaseURL("about:blank", finalSrc, "text/html", "UTF-8", null);
the finalSrc is a variable of html string.
sometimes, the webview can display the corrent content,but sometimes not.
and I found that if I clear the cache of my app, the webview works well again.
so what's wrong with my app?
rather than using BaseUrl why don't use loadData. for example
webview.loadData(finalSrc, "text/html", "UTF-8");
I have the URL of a webpage to be displayed into a webview in my Android app. Before showing this page i want to clear the html code of this page from some tag (such as the header, footer, ecc..) in order to show only few information. How can i do it? I tried to solve the issue working with JSoup but i can't understand how to create and pass the "new page" to the webview. Anybody can help me?
EDIT
I cleaned the html code useless through jsoup libraries. Then, always by mean of these, i get head and body content and finally i showing the "cleared" web page through these lines:
headURL = doc.select("head").outerHtml();
bodyURL = doc.select("body").outerHtml();
webview.loadData( "<html>"+headURL+bodyURL+"</html>" , "text/html", "charset=UTF-8");
webview.setWebViewClient(new DisPlayWebPageActivityClient());
The view shows the new page but do not load css files specified in the head(that has not been touched). Who can say me why?
You can fetch the WebPage you want to display as a string, parse and remove whatever you don't want and then load this string as data in your webview.
Something like:
String webContent = fetchPage(url);
String cleanedWebContent = cleanUp(webContent);
webView.loadData(cleanedWebContent, "text/html", "UTF-8");
Of course, you will need to implement fetchPage and cleanUp as they are not Android methods
I have some images that I loaded from a remote source stored in Bitmap variables and I want to display them. In addition to switching between these images the user should also be able to zoom and pan them. My first idea was to somehow pass them via an intent to the built-in gallery application but this doesn't seem to be possible.
A solution that is suggested in several places is using a WebView since it already supports zooming and panning.
My question is how does my Bitmap data get into the WebView? Do I have to write it to a file first, which I would have to remove again later, or is there an easier way?
Or are there even better ways to accomplish my main goal, which is displaying Bitmap data as zoomable and panable images?
You can just use webview to directly view your image remotely. You do not need to save anymore the image in a file.
Here is a sample code snippet.
myWebView.getSettings().setBuiltInZoomControls(true); //to get zoom functionalities
String url = "http://....."; //url of your image
String x= "<html><head><meta name=\"viewport\" content=\"width=device-width, minimum-scale=1.0\"/><style type=\"text/css\">html, body {margin: 0;padding: 0;} img {border: none;}</style><head><body style=\"background: black;\"><table><tr><td align=\"center\"><img src=\"" + url + "\" /></td></tr></table></body></html>";
myWebView.loadData(x, "text/html", "UTF-8");
About switching images, you can just change the value of the url and call the loadData again of the webview.
I wasn't satisfied with WebView after all so I ended up creating my own image viewing Activity. Further descriptions on how I did it can be found in this post on google groups.
I have to download contents of an HTML file (which uses image) via REST API. Then store them for offline use. When needed I want to display the HTML page with a WebView (of course with image). The REST result should look something like:
{
"id": 45,
"html": "<!DOCTYPE html><html><body><h1>My Heading</h1><p>My paragraph.</p><img src='abc.com/images/54289847.jpg' alt='any' width='104' height='142'></body></html>",
"imagePath": "abc.com/images/54289847.jpg",
"moreData": "something more"
}
So, what will be the most efficient way to do this?
I'm planning encrypted contents of HTML will go to local storage in any file. Same thing for the images. And then decrypt, and load to WebView. But will it work for images?
I don't need any code, just suggest me a way.
in this example string is loaded to webview
String summary = "You scored 192 points.";
webview.loadData(summary, "text/html", null);
what if you get string from input stream and pass it to web view IOUtils.toString(context.getResources().openRawResource())
Im not an android developer, but can't you get the "image data-url" and use as the image itself?
For example your avatar's data-url is:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADYUlEQVRYhe2W7UtTYRjGj2VqZSFC4AtSS+d8Wa5pKaWbnql7dVMsxEjDisjMVAoKkvxgUEFZhJVT6MWioBeCvkX0j/SxP0D6srOzuZ1zdZ9ztnl0x9cZEvjh5kx39jy/+7qv+34ehhnwYUtjG+D/AbiqipX+t+kA0uLDPhT2enCxw4VJuwNTLXb4Ke46HXCddiPzQtvCu5sKMOJDTbcH362tEA02oJgFypdECYs/lc2453Ag+3Lb+iGW/WLIi3HKEBUW2sQC7jCLQIV2CDGYOWMznKSIBJ4awDUvPrJ2oJBFuLMckTs54L1GBHQOBKoalwWRFdHb0N/uTAGA6MdclLmOBVdmQfRJBvCVgTiVicjoAYROlSNQbltZDYKwdLnXVo6lhjOf8QClNnDSgpVN4FkThIls4A0DfGIQ7tMhkOdBoMy2OFRQkhK/Tc1IG/CuE4Dc/oMMJy0gLyY9i5wItZohTmQCMwyio7ngm46BbzCDt1I0VNOzGsH6Ohk4AUGGvd7mXF0Fdfa6HsreEMuegjNbMD9cBFHK3p8GTDMyBGbTFEVmGeX5gcAIkKs9qUDHVPhV1wJmcBUV1ACDPie5fiF7ru4EhGc7gXeMsrlWzMRK01NCJl3wgpSEVEo9JbWiCuo/pmm4JOSPL6RvQWQoX9lIA0Cc3I35/iJwpc2J7NVl6O10rRHgig8/La1JAIGDDgXgrcbmM+ngJdmLXOCO1Ce3JcWljlQBaADN3yhILgMpIvozECSFeHcVIg+zwBmsKQAsUwKpvXjrUYgv0xcD+CneM7I6kZE8iGRITuoCdTuuqwRLTagC4IxNEJ9nLfjgxQ4I4/sRpQkZvZ0L8RUjl4i3mZSZsCETarRhwohkMOHRPgVgilrwdRqEx9kIn9XTHKhFdCwH+EydcJ6G1CHbBttQaxAljMgicitf3kR4sAfC010IdRkQtB6nDR0ItRuAL1SOwQL53Y0NIq1RrJoJvMuE8Lli2XBBtkbZSALV2RDyGYFvBHAzn4BSGcXqw6iYTSqF1BGyydSHEX2WgKL39yLcXQpB35jCYRSP+HGsBaEVZFLebqb3rfJvUjuO4xG/kFA2kqQrgchHsMmCORO7SRcSVTlqut1rv5L1beaVTGXMrbuULgXZkmv5v45tgK0G+At38NtPjlXm2AAAAABJRU5ErkJggg==
If you paste this in your computer's browser(as url) and/or in <img> tag, you'll see your avatar.