I have an android application that needs to ascertain its current location (Using Google Play Services LocationClient) and then send that location back to a server. This needs to happen in the background at regular intervals e.g. Every 5 minutes
This code is working very well and it generally delivers the locations every 5 minutes within a few seconds tolerance. The problem occurs when android can not get a fix. Under these conditions I was expecting the callback to be run after 5 minutes with a NULL location object, however this does not happen. The Application merely continues to look for locations without ever calling the callback.
I call my LocationClient's requestLocationUpdates method with a locationRequest object created as follows
locationrequest = LocationRequest.create();
locationrequest.setInterval(5 * 60 * 1000);
locationrequest.setFastestInterval(3 * 60 * 1000);
locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationrequest.setExpirationDuration(45 *1000);
locationclient.requestLocationUpdates(locationrequest, mPendingIntent);
I can not see a suitable way to have the LocationClient call me every 5 minutes, even when it is not able to get a location. I appreciate that I could have an alarm that goes off every 5 minutes and then sends the most recent location back to the server but I was hoping to handle the sending within the callback.
Has anyone else had to handle this situation, or have any idea how to address it?