I am trying to call the loadUrl method in a webview with the below url
http://stage.realtylog.net/iPhone/functions.php?username=xxx&ID=xxx&act=readFileAndPri
As Dino Fancellu pointed out, its a bad bug, but I think it only applies to the asset local files in your android project.
Incredibly enough, this bug did not exist in versions 2+ (Froyo).
And my app relied heavily on passing url variables to /asset/ files.
I was only passing one variable (?id=xx), but heres how i fixed it, and tweaked it to work with multiple variables:
// in App declare a string to hold the url parameters
String strUrlParams;
// In WebViewClient, Override the onReceiveError
// Basially check if params exist in Url, strip them and save them to string
private class HelloWebViewClient extends WebViewClient {
@Override
public void onReceivedError(WebView webview, int errorCode, String description, String failingUrl)
{
System.out.println("onReceivedError: " + description);
if (failingUrl.contains("?")) {
String[] temp;
temp = failingUrl.split(Pattern.quote("?"));
strUrlParams = temp[1]; // save params to string
webview.loadUrl(temp[0]); // load page without params
} else {
webview.loadUrl("file:///android_asset/error.html");
}
}
..........
}
// In JavascriptInterface, add method to return the params string
public String getUrlPString() {
return strUrlParams;
}
// In the webpage that is expecting the params, add javascript to grab them.
var getUrlParam = function(theParam) {
var strParam = "nada";
var query = window.location.search.substring(1);
if(query.indexOf("=") != -1) { // check if params
....
} else {
// no params in url, grab params string from app
query = app.getUrlPString();
}
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == theParam) {
strParam = pair[1];
}
}
return strParam;
}
// example to grab the ?id=xx param
var theID = getUrlParam("id");
Welcome to a horrible known bug, that Google doesn't feel like fixing, or even addressing.
http://code.google.com/p/android/issues/detail?id=17535