I have an aspx page which had already integrated google map api and can displayed the google map , then I want to show it in the android webview, but the webview can not be displayed the google map . this aspx page can run perfectly in android browser.
Here is Logcat print:
I / chromium: [INFO: CONSOLE (210)] "Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys ", source: http: //maps.google.com/maps-api-v3/api/js/25/11/util.js (210)
I / chromium: [INFO: CONSOLE (210)] "Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required ", source: http: //maps.google.com/maps-api-v3/api/js/25/11/util.js (210)
Here is the code about setting webview:
webView.getSettings().setJavaScriptEnabled(true);//
webView.getSettings().setGeolocationEnabled(true);//
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);//
webView.getSettings().setDatabaseEnabled(true);//
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
webView.getSettings().setBlockNetworkImage(false);
webView.getSettings().setBlockNetworkLoads(false);
String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
webView.getSettings().setGeolocationDatabasePath(dir);
Based from your code, I can't find the loadUrl
which loads the given URL
.
Compatibility note. Applications targeting N
or later, JavaScript state from an empty WebView is no longer persisted across navigations like loadUrl
. For example, global variables and functions defined before calling loadUrl(String) will not exist in the loaded page. Applications should use [ addJavascriptInterface(Object, String)
]( https://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object , java.lang.String)) instead to persist JavaScript objects across navigations.
To provide a WebView in your own Activity, include a in your layout, or set the entire Activity window as a WebView during onCreate():
WebView webview = new WebView(this);
setContentView(webview);
Then load the desired web page:
webview.loadUrl("http://slashdot.org/");
just add this line after webView.getSettings().setJavaScriptEnabled(true);//
webview.setWebViewClient(new WebViewClient());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.