Geolocation not enabled in webview on Android

Looking at the generated code, WebViewForeign.java, geolocation isn’t enabled in the webview. This stops you being able to run a location query in the browser which is a pain.

    public static Object CreateWebView321(final boolean zoomEnabled,final boolean scrollEnabled)
    {
        ScrollableWebView wv = new ScrollableWebView(com.fuse.Activity.getRootActivity());
        wv.getSettings().setJavaScriptEnabled(true);
        wv.getSettings().setUseWideViewPort(true); //enabled viewport meta tag
        wv.getSettings().setLoadWithOverviewMode(true); //mimic iOS Safari and Android Chrome
        wv.getSettings().setSupportZoom(zoomEnabled);
        wv.getSettings().setBuiltInZoomControls(zoomEnabled);
        wv.getSettings().setDomStorageEnabled(true);
        wv.setAllowScroll(scrollEnabled);
        
        return wv;
    }

Adding these lines would enable GPS location. They would have no effect unless the ACCESS_LOCATION and ACCESS_FINE_LOCATION permissions were set in the manifest which you can force by loading the FuseJS/Geolocation module.

       wv.getSettings().setGeolocationEnabled(true);
       wv.setWebChromeClient(new WebChromeClient(){
            @Override public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
                callback.invoke(origin, true, false);
            }
        });

My mistake, there is a webchromeclient created further up which means the code would need moving a little, I was posting before I tested.

In WebViewForeign.java add

wv.getSettings().setGeolocationEnabled(true);

and in FuseWebChromeClient.java add

import android.webkit.GeolocationPermissions.Callback;

...
...

		@Override public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
			callback.invoke(origin, true, false);
		}

Thanks for the input! I’ve logged a ticket about this now, so please check the progress there.

Thank you

I was too hasty typing in the code … check correction above. Simpler code but needs to be split into in 2 places. With code in place (some rapid copying while build happened) this is the result - a successful GPS location in WebView.

Please add those details to the ticket.

Uldis wrote:

Please add those details to the ticket.

Already done. Thank you.