Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Play Services for Android. Location client not update location if wifi disabled

Tags:

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.

like image 579
asivura Avatar asked Dec 02 '13 14:12

asivura


People also ask

Why won't my Google update my location?

Why is Google Maps not updating my location? If Google Maps is unable to update your location, this can be due to poor or unstable cellular data connection, GPS issues, low battery or running an outdated app version.

How do I force a location on my Android?

Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.

Can Android location be changed?

Recap. If you're interested in changing your GPS location, you have options. You can modify your location settings on your Android, modify your location settings within certain apps, or download software that lets you change your location.

What is Android location services?

The Google Location Services API, part of Google Play services, is the preferred way to add location-awareness to your app. It offers a simpler API, higher accuracy, low-power geofencing, and more. If you are currently using the android.


2 Answers

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.

like image 123
asivura Avatar answered Sep 29 '22 09:09

asivura


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".

like image 43
Andreas Avatar answered Sep 29 '22 10:09

Andreas