I'm having a big trouble working on an Android app that is supposed to encapsulate a web app and I'm thinking that StackOverflow is my only hope now.
The first problem was the following:
I needed to intercept the click on the "About" link to launch an Activity with our standard About view of all our apps. Unfortunately, when I click a link on the page, the content is loaded by AJAX and shouldOverrideUrlLoading(String url)
never gets called.
My workaround was to use Android's JavaScript interface to pass an object to JS so that it placed the loading URL to that object like this:
private class JavaScriptInterface {
@SuppressWarnings("unused")
public boolean shouldOverrideUrlLoading(String url) {
if (url.endsWith("about")) {
startActivity(new Intent("foo.bar.ABOUT"));
return true;
}
return false;
}
}
This is working perfectly and it doesn't look like a very ugly workaround at all.
The second problem is that, in Android 2.1 (phone and emulator), the WebView doesn't store AJAX loaded URLs in the history so, pressing back always exits the app even with the following code to override the back keypress:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
Strangely, this works perfectly in all versions of Android >2.1. Is there any workaround possible?
We were thinking about calling a JS function to know if I can go back in history but how can I call a JS function from Android and get its boolean return value?
Thanks very much in advance.