I'm fetching a url and trying to send it's text content to a javascript function inside a webview.
I do this from the java code:
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://volteck.net");
// Get the response
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response_str = client.execute(request, responseHandler);
response_str = response_str.replaceAll("\n", "\\");
// this is because js don't support multi-line strings
myWebView.loadUrl("javascript:myfunction('" + response_str + "')");
System.out.println("javascript:myfunction('" + response_str + "')");
This is code that is inside the webview:
function myfunction(val){
document.body.innerHTML = val.length;
}
So far I'm only trying to get the text length. But when I use the url of previous code, nothing happens. and I get this from the log:
08-19 23:55:03.141: I/dalvikvm-heap(1846): Grow heap (frag case) to 3.551MB for 262160-byte allocation 08-19 23:55:03.351: D/dalvikvm(1846): GC_FOR_MALLOC freed 0 objects / 0 bytes in 209ms
But the weird thing is that if I attempt to fetch volteck.net/ip, that only contains an IP number, it works just fine!
Thanks a lot from a Java newbie.