FusedLocationProviderClient - App stops receiving location updates on Foreground Service

Viewed 74

My app stops receiving location updates in a foreground service that has a loop to send telemetry data to a server. I use GCM (Firebase) to communicate with the app and I can kill the service and restart it remotely. If the service is receiving the location updates and I kill it when I restart it continues to send the location information.

But, for no apparent reason, it stops receiving location updates (the little arrow icon on the notification bar disappears and the telemetry data sent to the server shows no location [lat, long] info) and even if I kill and restart the service, the location is not passed forward.

It also occurs when I boot the cellphone with the service running. I can detect the boot and restart the service, but the location manager is not awakened, remains stationary.

If I click on the icon, it starts to receive location updates again.

I'm using the Fused Location Provider Client API.

public void requestLocationUpdates() {
    if (!isRequestingUpdates){
        Log.e(TAG, "requestLocationUpdates: Requesting location updates");
        isRequestingUpdates = true;

        try {
            mFusedLocationClient.requestLocationUpdates(mLocationRequest,
                    mLocationCallback, Looper.myLooper());
            Log.e(TAG, "requestLocationUpdates: inside Try");
        } catch (SecurityException unlikely) {
            isRequestingUpdates = false;
            Log.e(TAG, "Lost location permission. Could not request updates. " + unlikely);
        }
    }
}

Can anyone give me some pointers?

0 Answers
Related