20

Our app request update location with LocationClient and IntentService. Location doesn't update at all if user disable wifi in phone settings.

We tried to test app with PRIORITY_HIGH_ACCURACY and location updates when wifi disabled.

The same issue if user moving in the place where no wifi networks available.

I think correct behavior is use other phone sensors (like GPS) for update location if phone can not update location with wifi.

Steps to reproduce:

  1. Start update location with pending intent. With parameters

    LocationRequest request = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
            .setInterval(5 * 60 * 1000)
            .setFastestInterval(60*1000)
            .setSmallestDisplacement(70);
    
  2. Disable wifi in phone settings or go with phone in the country where no wifi networks available.

Tested on Android 4.4, 4.3, 4.1, 4.0, 2.3.3. (Nexus7, Nexus4, Samsung GS2, HTC Wildfire and others)

public class TrackerService extends IntentService {
    private void startUpdateLocation() {
        PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(),
            0, new Intent(ACTION_LOCATION_UPDATED), 0);
        LocationRequest request = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
            .setInterval(5 * 60 * 1000)
            .setFastestInterval(60*1000)
            .setSmallestDisplacement(70);

        getLocationClient().requestLocationUpdates(request, pendingIntent);
        Log.d(Utils.getMethodName(), "Location update started");
    }

    private LocationClient getLocationClient() {
        if (mLocationClient != null && mLocationClient.isConnected()) return mLocationClient;
        mLocationClient = new LocationClient(this,
            new GooglePlayServicesClient.ConnectionCallbacks() {
                @Override
                public void onConnected(Bundle bundle) {
                    Log.d(Utils.getMethodName(), "Location client. Connected");
                }

                @Override
                public void onDisconnected() {
                    Log.d(Utils.getMethodName(), "Location client. Disconnected");
                }
            },
            new GooglePlayServicesClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult connectionResult) {
                    throw new IllegalStateException("Failed connection to location manager " + connectionResult.toString());
                }
            }
        );
        mLocationClient.connect();
        try {
            while (mLocationClient.isConnecting()) {
                Thread.sleep(200);
            }
        } catch (InterruptedException e) {
            throw new IllegalStateException("Thread interrupted", e);
        }
        return mLocationClient;
    }
}

I tried to send bug report https://code.google.com/p/android/issues/detail?id=63110

Developers of Android can't help.

Where can I report about bugs in Google Play Services?

Is it a bug in Google Play Services?

What work around could you offer?

We don't want use PRIORITY_HIGH_ACCURACY because it drain phone battery. Our application tracking phone location and it shouldn't depends from wifi settings and wifi networks availability.

6
  • Did you get onConnected being called?
    – fasteque
    Dec 2, 2013 at 14:48
  • Yes. Our app in production. We found this issue few days ago . Location updating if I set PRIORITY_HIGH_ACCURACY in location request.
    – asivura
    Dec 2, 2013 at 14:51
  • I guess you test it changing your location of more than 100 meters, because of this comment in the doc: developer.android.com/reference/com/google/android/gms/location/…
    – fasteque
    Dec 2, 2013 at 14:58
  • I tried change it yesterday. Result doesn't change - no updates if wifi disabled.
    – asivura
    Dec 3, 2013 at 5:51
  • We have not found any solutions yet. We recommend users turn on WiFi. May be we'll have to move to Location Manager if Google not fix it.
    – asivura
    Jan 25, 2014 at 20:03

3 Answers 3

13

I found solution.

Google changed documentation for Location Client. Now it says:

public static final int PRIORITY_BALANCED_POWER_ACCURACY

Used with setPriority(int) to request "block" level accuracy.

Block level accuracy is considered to be about 100 meter accuracy. Using a coarse accuracy such as this often consumes less power.

Using a coarse accuracy - I think it means that Location Client doesn't use GPS for update location if priority is PRIORITY_BALANCED_POWER_ACCURACY.

So for using GPS you should use PRIORITY_HIGH_ACCURACY.

5
  • 4
    I am able to reproduce exactly this behavior, good catch, also WTF, Google.
    – nmr
    Jun 6, 2014 at 19:40
  • 2
    this is not working, even after PRIORITY_BALANCED_POWER_ACCURACY, onLocationChanged() is not call. No callback from requestLocationUpdates even after 1 hour
    – Akhil Jain
    Dec 2, 2014 at 9:59
  • 1
    More evidence: Emulator sending GPS data to emulated app while app is listening to PRIORITY_BALANCED_POWER_ACCURACY updates produces 0 onLocationChanged() events. When on PRIORITY_HIGH_ACCURACY onLocationChanged events are fired as fast as the GPS produces updates, completely ignoring setInterval.
    – Baker
    Sep 30, 2016 at 1:39
  • Testing on a physical phone while walking around, BALANCED mode works as intended with location changed events being sent at intervals specified by setInterval.
    – Baker
    Sep 30, 2016 at 18:09
  • I know this is old, but, you have to request permission ACCESS_FINE_LOCATION even for PRIORITY_BALANCED_POWER_ACCURACY. With ACCESS_COARSE_LOCATION the locations will have low accuracy (less than block level) and wont be able to access location given in emulator... Also the whole locationupdate API is veeery buggy.
    – fiLLLipnet
    Jul 7, 2017 at 6:29
6

Let me try to give you one answer to this. Up until a few minutes ago I was having the same problem and was hoping there would be an answer here.

I'll describe my problem and solution:

Problem: I didn't get any location updates without an internet connection while using Google Play services LocationClient. GPS enabled.

My code was stable and working with Internet available, but field tests failed.

Possible root causes: 1) LocationClient sucked 2) location client didn't get any gps updates

Solution: To test this I tried using the google maps app. It complained without an internet connection, so I gave it one. Then I tried to locate myself, but a new screen popped up saying that I had to allow "google apps" to access my location. It said that this would not affect 3rd party apps not from google, which turned out to be complete bullshit. When I enabled "only google apps" to access my location my own app suddenly kicked into action within seconds. Developing for android has been full of these "Google moments".

1

If someone is still wondering,

Google documentation says:

If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. Permission for ACCESS_COARSE_LOCATION allows access only to NETWORK_PROVIDER.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.