I use the FusedLocationProvider from GoogleAPIs to request location data. Sometimes, when I WIFI is turned off, it is not able to receive location data through GPS. GoogleApiClient gets connected successfully and I test it on a real device - so this shouldn't be the problem. My settings look like this:
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(4000);
mLocationRequest.setFastestInterval(2000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setNumUpdates(5);
The whole process works very well if WIFI is turned on and connected. Even if I turn WIFI on, get location data, turn it off again and then start updating location again it is working with new data. The missbehaviour is totally random in my view and I don't know why this happens sometimes (especially after device was turned off during night). I would expect it to use GPS to get new location data. By the way I can see the GPS icon in the status bar but I don't receive new data. The error which is shown in logcat is the following:
09-21 09:54:44.547 3947-27505/? W/System.err: java.net.UnknownHostException: Unable to resolve host "www.google.com": No address associated with hostname
09-21 09:54:44.547 3947-27505/? W/System.err: at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:125)
09-21 09:54:44.547 3947-27505/? W/System.err: at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)
09-21 09:54:44.547 3947-27505/? W/System.err: at java.net.InetAddress.getAllByName(InetAddress.java:752)
09-21 09:54:44.547 3947-27505/? W/System.err: at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
09-21 09:54:44.547 3947-27505/? W/System.err: at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:187)
09-21 09:54:44.547 3947-27505/? W/System.err: at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:156)
09-21 09:54:44.547 3947-27505/? W/System.err: at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:98)
09-21 09:54:44.547 3947-27505/? W/System.err: at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:345)
09-21 09:54:44.547 3947-27505/? W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
09-21 09:54:44.548 3947-27505/? W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
09-21 09:54:44.548 3947-27505/? W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
09-21 09:54:44.548 3947-27505/? W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
09-21 09:54:44.549 3947-27505/? W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)
09-21 09:54:44.549 3947-27505/? W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
09-21 09:54:44.550 3947-27505/? W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
09-21 09:54:44.550 3947-27505/? W/System.err: at akkl.a(:com.google.android.gms:89)
09-21 09:54:44.550 3947-27505/? W/System.err: at amcc.run(:com.google.android.gms:289)
09-21 09:54:44.550 3947-27505/? W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
09-21 09:54:44.550 3947-27505/? W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
09-21 09:54:44.550 3947-27505/? W/System.err: at java.lang.Thread.run(Thread.java:761)
09-21 09:54:44.550 3947-27505/? W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
09-21 09:54:44.550 3947-27505/? W/System.err: at libcore.io.Posix.android_getaddrinfo(Native Method)
09-21 09:54:44.550 3947-27505/? W/System.err: at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
09-21 09:54:44.550 3947-27505/? W/System.err: at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:106)
09-21 09:54:44.550 3947-27505/? W/System.err: ... 19 more
So do I really need WIFI at least one time to get data via GPS? And is there a possibility like a timeout so I can tell the user "Hey you need Wifi to get location data"? Checking the network connection is not an option because as mentioned above it is working most times without WIFI.