我有一个aspx页面,已经集成了google地图api并且可以显示google地图,然后我想在android webview中显示它,但是webview无法显示google地图。 这个aspx页面可以在android浏览器中完美运行。
这是 Logcat 打印:
I / chromium:[信息:控制台(210)]“Google Maps API 警告:NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys”,来源:http://maps.google.com/maps-api-v3/api/js/25/11/util.js (210)
I / chromium:[信息:控制台(210)]“Google Maps API 警告:SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required”,来源:http://maps.google.com/maps-api-v3/api/js/25/11/util.js (210)
这里是设置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);
只需在
webView.getSettings().setJavaScriptEnabled(true);//
之后添加以下行
webview.setWebViewClient(new WebViewClient());
根据您的代码,我找不到加载给定
loadUrl
的URL
。
兼容性说明。面向
N
或更高版本的应用程序,空 WebView 中的 JavaScript 状态不再跨导航(如 loadUrl
)持久保留。例如,在调用 loadUrl(String) 之前定义的全局变量和函数将不会存在于加载的页面中。应用程序应该使用 [addJavascriptInterface(Object, String)
](https://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String)) 来保留 JavaScript跨导航的对象。
要在您自己的 Activity 中提供 WebView,请在布局中包含一个 WebView,或者在 onCreate() 期间将整个 Activity 窗口设置为 WebView:
WebView webview = new WebView(this);
setContentView(webview);
然后加载所需的网页:
webview.loadUrl("http://slashdot.org/");