Reputation: 2178
I am trying to show a map which animates percentages for several areas on the map. But the javascript (which works in the browser) doesn't show any animation or percentage at all. The webmpa.generateJs() generates the javascript to animate the percentages and the function initialize is used to draw the map.
WebSettings settings = webView.getSettings();
settings.setAppCacheEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setJavaScriptEnabled(true);
final WebMap webMap = new WebMap();
webView.addJavascriptInterface(webMap.getInterface(getActivity().getApplication(),this), "Android");
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
Log.d(TAG,webMap.generateJs());
webView.loadUrl("javascript:" + webMap.generateJs());
webView.loadUrl("javascript:initialize();");
}
});
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
webView.setBackgroundColor(Color.TRANSPARENT);
webView.loadUrl(MAP_URL);
Upvotes: 5
Views: 1563
Reputation: 5543
Just to add to Satish's answer, in case you're using proguard use this in your project's proguard file:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
Upvotes: 1
Reputation: 4335
You have to use WebChromeClient for your purpose.
webView.setWebChromeClient(new WebChromeClient());
This may helps you
Upvotes: 1