In our application, we used the Fused Location Provider (FLP) provider to track location. We noticed that sometimes an application can get into a state when a callback request for a location ceases to be called. This application is mainly used on two tablets (nexus 7 and LG G-pad 8.3). We saw that the problem occurs on both devices. Typically, resetting the device seems to alleviate the problem. We believe that we adhere to most of the best practices for using FLP. But just in case, we've put together this sample code that illustrates how we use FLP.
Get the google api client and call connect:
m_googleApiClient = builder .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); m_googleApiClient.connect()
After connecting, we start listening to location callbacks:
@Override public void onConnected(Bundle bundle) { m_fusedLocationProviderApi.requestLocationUpdates(m_googleApiClient, m_locationRequest, this); }
The location request is as follows:
LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS); locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
Then we implement the callback as follows:
@Override public void onLocationChanged(Location location) {
When problems arise, we do not receive any callbacks. We also tried calling reset () on the google api client when we find that we have not received GPS for a long time. We also control the availability of the location using a timer every 2 seconds (using getLocationAvailability). As a rule, we find that having a user reset their device (turning it on, turning it off) fixes the problem.
Our questions:
- Has anyone else noticed this problem with FLP?
- Is there anything else you can do to solve the problem without having user reset? Would you delete location update help?
- Is there more information we can / should collect to diagnose the problem?
android google-play-services fusedlocationproviderapi gps location-services
noahd
source share