I have tried everything and still doesn't work, please help:
I setup my WebView here:
public class MainActivity extends ActionBarActivity {
private WebView mWebView;
private MyWebViewClient mWebViewClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
mWebViewClient = new MyWebViewClient(context);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.addJavascriptInterface(mWebViewClient, "Android");
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setDomStorageEnabled(true);
mWebView.setWebViewClient(mWebViewClient);
mWebView.loadUrl("file:///android_asset/index.html");
}
}
This is where I call my function from JS:
<script>
$("#logInButton").click(function(){
if(isAndroid){
Android.onJavaLogIn();
}
return false;
});
</script>
<input type="button" value="Log In" id="logInButton" />
Here is how I handle it:
public class MyWebViewClient extends android.webkit.WebViewClient {
private MainActivity context;
public MyWebViewClient(MainActivity context) {
this.context = context;
}
@JavascriptInterface
public void onJavaLogIn(){
context.onMainLogIn();
}
}
public class MainActivity extends ActionBarActivity {
public void onMainLogIn(){
mWebView.loadUrl("javascript:onJSLogIn();");
}
}
This is the JS function it's suppose to call:
<script>
function onJSLogIn(){
$("#logInButton").hide();
$("#logOutButton").show();
}
</script>
The entire chain seem to be correct, and I verify via debug that onMainLogIn() in MainActivity does get called, but the JS function onJSLogIn() never get called, why?