problem in display image with loadDataWithBaseURL() in Android - android

In my Application, I display data in webview but it can't display the images in the webview.
I used loadDatawithBaseURL() method.
This is my code..
webview.loadDataWithBaseURL("file:///059600656X/", data, "text/html", "UTF-8", "about:blank");
// here data is a string object which contain html parsing data.
I think it cant find the images in given directory.
Can Anybody help me?

You cannot use simple file:/// URLs with loadDataWithBaseURL(), and "about:blank" probably is not a valid base URL.

To make the loadDataWithBaseURL work you need to make sure of two things:
All image src include "file:///android_asset/imagename"
and the images are in the asset folder!!
So contrary to answer1, it is as simple as that!
Munir Syed

When you use LoadDataWithBaseURL you must specify the image resource as ur baseurl and data must be ur array or image renderer.
example
wv.loadDataWithBaseURL("file:///android_asset/", srray[position], "text/html", "UTF-8", null);
this should help me out

Related

How to scroll Android WebView programmatically to a specific element

I load an HTML string directly into a WebView with loadDataWithBaseURL(null, html, null, null, null) and later I'd like to be able to scroll programmatically to an internal element, e.g. <p id="pos1"> or <a name="pos1"></a>
I found a similar question, where the answer was to use javascript:
https://stackoverflow.com/a/2239301/2534762
But is that really the only way? Isn't there another simple way to say directly to a WebView: "go to #pos1" without having to embed a script in every HTML page that you want to scroll? It seems to me a common task begging for a simple solution, but apparently I'm wrong... or is there a way to do that, maybe calling loadUrl or loadDataWithBaseURL in some particular way?
I found that I don't need to embed JavaScript in the HTML page, as suggested in that other answer, I can instead write one line of JavaScript directly in the URL:
webView.loadUrl("javascript:document.getElementById('"+aID+"').scrollIntoView()");

How to Modify content of resource response android webview

What I'm trying to do is to intercept the response data and modify the response from a particular URL.
For example, when loadUrl("http://foo.bar") is called to a WebView, let's say that it will load "page.html", "data.json", "someimage.png", and so on. In this case, how can I modify the contents of data.json when the resource is fetched, and pass the modified file to the WebView?
I think shouldInterceptRequest might be the answer, but I can't figure out how to get a WebResourceResponse from a WebResourceRequest.
I'm sorry if my English is awkward ;(

Web View in Android

In my android app whole web page is loading in web view to which i gave the link, but I want to load only some component from that web page not rest of the component. Can anybody tell me is it possible to load only required component from web page and how?
It can be done using Jsoup html parsing library.
1.Get the data from url to jsoup document.
Document doc = Jsoup.connect("http://example.com/").get();
remove the unwanted content html tag using remove().
doc.select("span[style*=display:none]").remove(); //put unwanted tag inside.
Save the remaining content to a string.
String newcontent=doc.toString();
4 Set the newcontent as Webview content.
webView.loadDataWithBaseURL(null, newcontent, "text/html", "UTF-8", null);
Sorry for poor english.
I dont know if there is a standard api to do this, but if not you could load the html first then manipulate it. So you could delete the areas you dont need and only display the necessary parts.
Cheers

Android webView; Not displaying image having relative path

While trying to use loadUrl(String url, Map additionalHttpHeaders) method of webView, the response that I receive is not able to display the image. Instead of the image, a question mark substitute is used.
So, I tried to hit the same URL using Java code. The HTML code received during this process showed that the tag's src attribute was using a relative location.
On passing this same HTML code to webView's loadData() method, I get the same output as mentioned in the first case.
Anyway to fix this issue? (In the additionalHttpHeaders I was passing the authorization header)

How to use an XML data from an URL link?

The title maybe a little confusing so I shall explain a lot more details here. First off, I have an URL link that uses HTTPS secured site. I already managed a successful attempt to use a WebView to connect to the site, using loadDataWithBaseURL method.
The URL link does not end with .xml, so I am stuck with this problem. What are the procedures to do in order I can use the xml data on an URL link that does not ends with .xml?
EDIT:
<MGMT>
<NET>
<HEAD>
<ClientID>99999999</ClientID>
<ServerID>WEB_01</ServerID>
<Rsp>00</Rsp>
<Auth></Auth>
</HEAD>
<STAT>
<IP>192.168.5.158</IP>
<Status>OK, Success!</Status>
</NET>
</MGMT>
I do have XML parsing knowledge. But that is if the url link returns a XML data or I have an XML file. This is NOT THE ACTUAL LINK but it is similar, I changed a few values in it.
https://192.168.0.254/?ClientID=999999&Cert=0f7a248e3b017effec2b36cf53912b0f&IP=192.168.5.128
Ok. As i come to know about your question, you have to gain some knowledge about xml parsing which convert the fetched XML data in to specific variables.
Here in below examples, the project get the Http responce from the server which is in the formate of the xml file. (Which URL not having .XML extention). And that data are stored in to specific variable.
You have to fetch various data based on the tab as per your xml structure. as like "MGMT", "NET" . . .etc etc. . .
See this: Example 1
Also see this: Exapmple 2
Hope you got the Logic to do it.

Categories

Resources