4

I'm trying to enable the WebView to get location with mobile data (3g/lte) but the location is received only when I use WiFi/enable wifi scanning.

Here's a log of the location request printed by the system when using mobile data:


LocationManagerService: requestLocationUpdates: uid=11294, pid=17340, provider=fused, package=com.my.package listener= android.location.ILocationListener$Stub$Proxy@713f86 intent= null

For some reason the location is never received and the WebView stays in looking for location state.

If the Wifi is on or enabled to always scan even when off, it works very fast on both wifi or mobile data


LocationManagerService: requestLocationUpdates: uid=10014, pid=3464, provider=gps, package=com.google.android.gms listener= android.location.ILocationListener$Stub$Proxy@6f09c54 intent= null

Fused alone doesn't work, only if GPS provider is requested.


Relevant granted permissions:
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"

My webview settings:


mWebView.settings.domStorageEnabled = true
mWebView.settings.builtInZoomControls = true
mWebView.settings.loadWithOverviewMode = true
mWebView.settings.useWideViewPort = true
mWebView.settings.displayZoomControls = false
mWebView.settings.mediaPlaybackRequiresUserGesture = false
mWebView.settings.setAppCacheEnabled(true)
mWebView.settings.databaseEnabled = true
mWebView.settings.domStorageEnabled = true
mWebView.settings.javaScriptEnabled = true
mWebView.settings.allowContentAccess = true
mWebView.settings.javaScriptCanOpenWindowsAutomatically = true
mWebView.settings.setGeolocationEnabled(true)
mWebView.settings.setGeolocationDatabasePath(context.filesDir.path)

The ChromeClient:


mWebView.webChromeClient = object : WebChromeClient() {

            override fun onGeolocationPermissionsShowPrompt(origin: String?, callback: GeolocationPermissions.Callback) {
                super.onGeolocationPermissionsShowPrompt(origin, callback)

                OLog.i(tag(), "Requesting location")
                callback.invoke(origin, true, true)
            }
        }
    
Lior Iluz
  • 26,213
  • 16
  • 65
  • 114

0 Answers0