webview dont ask "share location" problem

Ram

Member
Licensed User
Longtime User
when pointing webview to a page that has this kind of function:

B4X:
<html>
<head>
<script type="text/javascript">
// Check for geolocation support
if (navigator.geolocation) {
   // Use method getCurrentPosition to get coordinates
    navigator.geolocation.getCurrentPosition(function (position) {
        // Access them accordingly
        document.getElementById("Latitude").value = position.coords.latitude;
        document.getElementById("Longitude").value = position.coords.longitude;
    });
}
else
   alert("no geo-location support");
</script>
</head>
<body>
Latitude:<input type="text" id="Latitude" name="Latitude" value="?" />
Longitude:<input type="text" id="Longitude" name="Longitude" value="?" />
</body>
</html>

with most browsers i get "would you like to share your location?" and if agree then get the location in return, however when using webview i get the page without any alert, share permission question nor results..

any advice will be highly appreciated! :sign0085:

Thx & Best,
R.
 

warwound

Expert
Licensed User
Longtime User
As Erel pointed out - the default B4A WebView does not support modal dialogs.

So if the javascript navigator.geolocation returns false then the alert dialog will not be displayed.
And if the javascript use of navigator.geolocation would normally show a prompt (to allow/disallow) then that prompt will not be displayed either.

So you need to add the WebChromeClient to your WebView to enable modal dialogs.

But WebViewExtras will i think need an update.
Take a look at the documentation: WebChromeClient | Android Developers.
Scroll down that page to onGeolocationPermissionsHidePrompt and onGeolocationPermissionsShowPrompt.

It looks as though i'll need to implement those two methods in WebViewExtras so that the WebChromeClient properly asks the user for permission for the web page to use the Geolocation methods.

Can you try to simply use WebViewExtras and it's addWebChromeClient method and post with your results?

It may be that the default WebChromeClient already shows the required dialogs but i suspect not.

Post again with your results and if required i'll try and update the WebChromeClient to support the Geolocation prompts.

Martin.
 
Upvote 0

Ram

Member
Licensed User
Longtime User
will do

@Martin

thank you very much for your answer! i will re try and post my results once ill have some progress, once again, thx much!
 
Upvote 0

Ram

Member
Licensed User
Longtime User
no joy

@Martin

using addWebChromeClient did help me with my tests to show java scripts alerts msg's from my web page but it does not show the permission alert.

I found this code that automatically allow the location permission but i have absolutely no clue on how to implement it or if its possible all together :sign0104::

B4X:
mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
            public void onGeolocationPermissionsShowPrompt(String origin, 
                                                           GeolocationPermissions.Callback callback) 
            {
                  callback.invoke(origin,true,false);
            }               
       });     
 }
 
Upvote 0
Top