Android webview obtains Geolocation and webviewgeolocation
<Uses-permission android: name = "android. permission. INTERNET"/>
<Uses-permission android: name = "android. permission. ACCESS_FINE_LOCATION"/>
<Uses-permission android: name = "android. permission. ACCESS_COARSE_LOCATION"/>
Private WebViewwebView = null;
Private WebSettingswebSettings = null;
Private void initWeb (){
WebView = (WebView) this. findViewById (R. id. webView_load );
WebView. GetSettings (). setJavaScriptEnabled (True);
LoadURL (urlStr );
SetClient ();
WebSettings = webView. getSettings (); // sets the default attribute on the webpage.
WebView. setInitialScale (39); // adapts to the portrait Screen
WebView. setScrollBarStyle (View. SCROLLBARS_INSIDE_OVERLAY); // remove the scroll bars at the bottom and on the right.
// WebSettings. setRenderPriority (RenderPriority. HIGH); // improves the rendering priority.
WebSettings. SetJavaScriptEnabled (True); // Sets whether interaction is allowed.Javascript
WebSettings. setAllowFileAccess (true); // enable or disable WebView from accessing File data
WebSettings. setLayoutAlgorithm (LayoutAlgorithm. SINGLE_COLUMN); // you can specify the display mode.
WebSettings. setdefazoom zoom (ZoomDensity.MEDIUM); // Adapt to the screen
// WebView. getSettings (). setUseWideViewPort (true); // whether to scale proportionally
WebView. getSettings (). setLoadWithOverviewMode (true); // zoom to the screen size
// WebView. getSettings (). setUseWideViewPort (true); // whether to scale proportionally
WebSettings. setBuiltInZoomControls (false); // you can specify whether scaling is supported.
// WebSettings. setsuppzoom zoom (false); // sets whether Zoom is supported. You can only double-click zoom.
WebSettings. setNeedInitialFocus (false); // you can specify whether a file can be accessed.
// WebSettings. setBlockNetworkImage (true); // load the image to the end and load the rendering
// WebSettings. setCacheMode (WebSettings. LOAD_CACHE_ELSE_NETWORK );//
// Set the cache Mode
WebSettings. setCacheMode (webSettings. LOAD_NO_CACHE); // No cache is used.
WebView. addJavascriptInterface (new Scan2 (), "mMap"); // The name here is the alias of window. fxl. testFunction () on the page.
WebView. addJavascriptInterface (new Scan2 (), "phone"); // The name here is the alias of window. fxl. testFunction () on the page.
// Key setGeolocationEnabled
WebView. GetSettings (). setGeolocationEnabled (true );
}
Private void setClient (){
WebView. setWebChromeClient (new WebChromeClient (){
@ Override
Publicvoid onGeolocationPermissionsShowPrompt (String origin,
Android. webkit. GeolocationPermissions. Callback callback ){
Callback. invoke (origin, true, false );
Super. onGeolocationPermissionsShowPrompt (origin, callback );
}
}