1 year ago

#164108

test-img

John Smith

What is the best method of getting background location updates on Android 11+ every few minutes

I have tried several approaches to getting background updates at least every two minutes automatically from Android 11+ Location providers and none of them seem to be reliable beyond using LocationServices which affects battery life a lot. Right now, I'm trying to use Geofences but it seems to never get a trigger unless I bring up Google Maps. I'm using the Emulator and switching locations manually using extended controls. It's not that it's not working. It's not getting renewed updates. When I start the app, I get the initial trigger from

GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
builder.addGeofences(geofenceList);

I also have

   geofenceList.add(new Geofence.Builder()
        // Set the request ID of the geofence. This is a string to identify this
        // geofence.
        .setRequestId(String.valueOf(iAlertCount))

        .setCircularRegion(
            dLatitude,
            dLongitude,
            AppInit.LOCATION_DISTANCE
        )
        .setNotificationResponsiveness(10000)
        .setExpirationDuration(Geofence.NEVER_EXPIRE)
        .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
            Geofence.GEOFENCE_TRANSITION_EXIT)
        .build());

I am also loading a Notification Icon service using startForegroundService as I read that having a foreground service should help.

I appreciate any input on this. I'm trying to avoid using LocationServices if I can get a reliable trigger at least every two minutes.

android

gps

geofencing

0 Answers

Your Answer

Accepted video resources