Android WebView Get geolocation

Source: Internet
Author: User
<span id="Label3"></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><uses-permission android:name= "android.permission.INTERNET"/></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><uses-permission android:name= "android.permission.ACCESS_FINE_LOCATION"/><br><uses-permission android:name= "android.permission.ACCESS_COARSE_LOCATION"/></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="white-space:pre"></span></p></p><p style="color:rgb(51,51,51); margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:rgb(147,26,104)"> <span style="white-space:pre"></span> Private</span> WebView<span style="color:#0326cc">WebView</span> =<span style="color:#931a68">null</span>;</p></p><p style="color:rgb(51,51,51); margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#931a68"> <span style="white-space:pre"></span> Private</span> WebSettings<span style="color:#0326cc">websettings</span> =<span style="color:#931a68">null</span>;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><br></p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#931a68"> <span style="white-space:pre"></span> Private</span> <span style="color:#931a68">void</span> Initweb () {</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>WebView = (webView)<span style="color:#931a68"></span>this. findviewbyid (r.id. <span style="color:#0326cc"> <span style="white-space:pre"></span> </span> <span style="color:#0326cc"> Webview_load</span>);</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span><span style="color:#0326cc"><u> <span style="white-space:pre"></span> WebView</u></span> <span style="text-decoration:underline">. GetSettings (). setjavascriptenabled (</span><span style="color:#931a68"><u>true</u></span><span style="text-decoration:underline">)</span>;</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span><span style="white-space:pre"></span>Loadurl (<span style="color:#0326cc">urlstr</span>);</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span><span style="white-space:pre"></span>Setclient ();</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>WebSettings =<span style="color:#0326cc">webView</span>. GetSettings (); <span style="color:#0326cc"> <span style="white-space:pre"></span> </span> <span style="color:#4e9072">//page Set default Properties</span></p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>WebView. setinitialscale (39); <span style="color:#0326cc"> <span style="white-space:pre"></span> </span> <span style="color:#4e9072">//adapt to vertical screen</span></p></p><p style="color:rgb(3,38,204); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(3,38,204); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="white-space:pre"></span>WebView<span style="color:#000000">. Setscrollbarstyle (View.</span> Scrollbars_inside_overlay<span style="color:#000000">);</span> <span style="color:#4e9072">//remove the bottom and right scroll bars</span></p></p><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="white-space:pre"></span>Websettings.setrenderpriority (renderpriority.high);//increase Rendering Priority</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span><span style="color:#0326cc"><u> <span style="white-space:pre"></span> websettings</u></span> <span style="text-decoration:underline">. setjavascriptenabled (</span><span style="color:#931a68"><u>true</u></span><span style="text-decoration:underline">)</span>; <span style="color:#4e9072">//set Whether you can interact</span> <span style="color:#4e9072"><u>Javascript</u></span></p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>Websettings. setallowfileaccess (<span style="color:#931a68">true</span>); <span style="color:#0326cc"> <span style="white-space:pre"></span> </span> <span style="color:#4e9072">//enable or disable webview access to file data</span></p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>Websettings. setlayoutalgorithm (layoutalgorithm. <span style="color:#0326cc"> <span style="white-space:pre"></span> </span> <span style="color:#0326cc"> Single_column</span>); <span style="color:#4e9072">//set display Mode</span></p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span><span style="color:#0326cc"> <span style="white-space:pre"></span> websettings</span>. <span style="text-decoration:underline line-through">Setdefaultzoom</span> <span style="text-decoration:underline">(zoomdensity.</span> <span style="color:#0326cc"><u>MEDIUM</u></span> <span style="text-decoration:underline">)</span>; <span style="color:#4e9072">//adaptation Screen</span></p></p><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="white-space:pre"></span>Webview.getsettings (). setusewideviewport (true);//whether any scale scaling</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>WebView. getsettings (). Setloadwithoverviewmode (<span style="color:#931a68">true</span>); <span style="color:#0326cc"> <span style="white-space:pre"></span> </span> <span style="color:#4e9072">//zoom to the size of the screen</span></p></p><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="white-space:pre"></span>Webview.getsettings (). setusewideviewport (true);//whether any scale scaling</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>Websettings. Setbuiltinzoomcontrols (<span style="color:#931a68">false</span>); <span style="color:#0326cc"> <span style="white-space:pre"></span> </span> <span style="color:#4e9072">//set Whether zooming is supported</span></p></p><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="white-space:pre"></span>Websettings.setsupportzoom (false);//set Whether zoom is supported, only double-click Zoom is supported</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>Websettings. Setneedinitialfocus (<span style="color:#931a68">false</span>); <span style="color:#0326cc"> <span style="white-space:pre"></span> </span> <span style="color:#4e9072">//set whether files can be accessed</span></p></p><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="white-space:pre"></span>Websettings.setblocknetworkimage (true);//load picture at last load render</p></p><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="white-space:pre"></span>Websettings.setcachemode (websettings.load_cache_else_network);//</p></p><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="white-space:pre"></span>Setting the cache mode</p></p><p style="color:rgb(3,38,204); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(3,38,204); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="white-space:pre"></span>WebSettings<span style="color:#000000">. Setcachemode (</span>websettings<span style="color:#000000">.</span> <span style="text-decoration:underline">Load_no_cache</span> <span style="color:#000000">);</span> <span style="color:#4e9072">//do not use cache</span></p></p><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb (78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco">< Span style= "color: #000000" ><span style="white-space:pre"> </span> <span style="color: #0326cc"><span style=" White-space:pre "> </span> webView </span> <span style=" color: #000000 ">.addjavascriptinterface (</span> <span style="Color:" #931a68 ">new </span> <span style=" color: #000000 "> Scan2 (), </span> <span style=" color: #3933ff ">" mMap "</span> Span style= "color: #000000"); The name here is the alias that is taken on page window.fxl.testFunction () </p></p><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(78,144,114); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#000000"><span style="white-space:pre"></span></span><span style="color:#0326cc"> <span style="white-space:pre"></span> WebView</span> <span style="color:#000000">. Addjavascriptinterface (</span><span style="color:#931a68">new</span> <span style="color:#000000"> Scan2 (),</span><span style="color:#3933ff">"phone"</span><span style="color:#000000">);</span> The name here is the alias that is taken on page window.fxl.testFunction ()</p></p><p style="text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco; min-height:15px"><p style="text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco; min-height:15px"><span style="color:rgb(51,51,51)"></span><span style="color:#ff0000"><span style="white-space:pre"></span>Key <span style="font-family:Monaco; font-size:11px; line-height:26px; white-space:pre">setgeolocationenabled</span></span></p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco; min-height:15px"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco; min-height:15px"><span style="color:rgb(3,38,204)"> <span style="white-space:pre"><strong></strong></span> webView <span style="white-space:pre"></span> </span> <strong>. GetSettings (). setgeolocationenabled (<span style="color:rgb(147,26,104)">true</span>);</strong></p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>}</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><br></p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="color:#931a68"> <span style="white-space:pre"></span> Private</span> <span style="color:#931a68">void</span> setclient () {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco">WebView. setwebchromeclient (<span style="color:#931a68">new</span> webchromeclient () { <span style="color:#0326cc"> <span style="white-space:pre"></span> <span style="white-space:pre"></span> </span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco; color:rgb(119,119,119)"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco; color:rgb(119,119,119)"><span style="white-space:pre"></span><span style="white-space:pre"></span>@Override</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span><span style="color:#931a68"> <span style="white-space:pre"></span> </span> public <span style="color:#931a68">void</span> ongeolocationpermissionsshowprompt (String origin,</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span><span style="white-space:pre"></span>Android.webkit.GeolocationPermissions.Callback Callback) {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span><span style="white-space:pre"></span>Callback.invoke (origin,<span style="color:#931a68">True</span>, <span style="color:#931a68">false</span>);</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>Super Ongeolocationpermissionsshowprompt (origin, callback); <span style="color:#931a68"> <span style="white-space:pre"></span> </span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>}</p></p><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><p style="color:rgb(51,51,51); text-align:left; margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Monaco"><span style="white-space:pre"></span>}</p></p><p><p>Android WebView Get geolocation</p></p></span>

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.