Android webview obtains Geolocation and webviewgeolocation

Source: Internet
Author: User

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 );

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.