Android WebChromeClient WebView onGeolocationPermissionsShowPrompt never fired -


i have webpage watchposition call works fine in regular browsers. however, dialog requesting gps permission never shows when webpage loaded webview webchromeclient , ongeolocationpermissionsshowprompt never called.

public class geowebchromeclient extends webchromeclient {      public void ongeolocationpermissionsshowprompt(string origin, android.webkit.geolocationpermissions.callback callback) {          log.d("geolocation permission", "permission >>>"+origin);          callback.invoke(origin, true, false);      } }   public class geowebviewclient extends webviewclient {      @override     public void onreceivedsslerror (webview view, sslerrorhandler handler, sslerror error) {         handler.proceed();     }      public boolean shouldoverrideurlloading(webview view, string url) {         // when user clicks hyperlink, load in existing webview         view.loadurl(url);         return true;     } }  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      webview browser = (webview) findviewbyid(r.id.browser);      websettings websettings = browser.getsettings();      websettings.setjavascriptenabled(true);     websettings.setjavascriptcanopenwindowsautomatically(true);     websettings.setappcacheenabled(true);     websettings.setdomstorageenabled(true);     websettings.setgeolocationenabled(true);      browser.setwebviewclient(new geowebviewclient());     browser.setwebchromeclient(new geowebchromeclient());      browser.loadurl("http://192.168.1.102/");   }  <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"/> <uses-permission android:name="android.permission.access_gps" /> <uses-permission android:name="android.permission.access_assisted_gps" /> <uses-permission android:name="android.permission.access_location" /> <uses-permission android:name="android.permission.access_fine_location" /> 

ongeolocationshowprompt doesn't show prompt itself, method gets called when page requests geolocation. you'll need create own prompt user shown below (placed inside ongeolocatioonshowprompt method):

final boolean remember = true; alertdialog.builder builder = new alertdialog.builder(this); builder.settitle("locations"); builder.setmessage(origin + " use current location").setcancelable(true).setpositivebutton("allow",                             new dialoginterface.onclicklistener() {                                 @override                                 public void onclick(dialoginterface dialog,                                         int id) {                                     // origin, allow, remember                                     callback.invoke(origin, true, remember);                                 }                             })                     .setnegativebutton("don't allow",                             new dialoginterface.onclicklistener() {                                 @override                                 public void onclick(dialoginterface dialog,                                         int id) {                                     // origin, allow, remember                                     callback.invoke(origin, false, remember);                                 }                             }); alertdialog alert = builder.create(); alert.show(); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -