I am calling JavaScript via WebView. This is my code:
public class MyWebViewClient extends WebViewClient {
.....
@Override
public void onPageFinished(final WebView view, final String url) {
super.onPageFinished(view, url);
view.loadUrl("javascript:Android.showAdBanner(showSdkAd())");
view.loadUrl("javascript:Android.updateUrl(appUrl())");
}
}
public class WebViewJavaScriptInterface {
....
@JavascriptInterface
public void showAdBanner(boolean appUrl) {
if (appUrl) {
...
} else {.....}
}
@JavascriptInterface
public void updateUrl(String appUrl) {
if (appUrl.isEmpty()) {
....
}
if (appUrl.equals("m.url.de")) {
....
}
}
}
showSdkAd()
returns a boolean
value and appUrl()
returns a String
.
The problems is that I get the wrong values, always false
when the showSdkAd()
function is called and an empty String
from appUrl()
.
I've already checked it and it works on the server side, so the problem should be on my side.
Does anybody have an idea?