srj
srj

Reputation: 90

Android WebView navigator.getCurrentPosition issues

Trying to load JS page in webview which has code: navigator.getCurrentPosition

a) For the same code in chrome browser of android app, I am seeing a pop up

enter image description here

to turn on location from settings automatically if user allows. But when loading the JS page in webview am not seeing the pop up window to turn on location.

Have already given :

 webview.setWebChromeClient(new WebChromeClient() {
            public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
                // callback.invoke(String origin, boolean allow, boolean remember);
                callback.invoke(origin, true, true);
            }
}

Upvotes: 1

Views: 289

Answers (1)

srj
srj

Reputation: 90

I have found answer to the question, Here it goes.

Basically for Google chrome Mobile Application the option for location settings is displayed to the user by intercepting onGeolocationPermissionsShowPrompt.

Make sure the callback passed on success of Locations settings is callback.invoke(origin, true, false); and failure is callback.invoke(origin, false, false);

All the boiler plate as mentioned in https://developer.android.com/training/location/change-location-settings is written in the callback onGeolocationPermissionsShowPrompt itself.

I noticed this not even done by other browser apps like firefox.

Upvotes: 1

Related Questions