Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are good strategies for dealing with background location limits for apps running on O devices?

Given the limits placed on location gathering on Android apps running in the background on O devices, what are good options for developers who want more frequent location updates?

I realize that O is still in developer preview, but there are significant changes to how location can be gathered in the background, and I want to project ahead to changes that might be needed in my apps.

like image 935
Shailen Tuli Avatar asked Dec 06 '25 20:12

Shailen Tuli


2 Answers

Apps requesting location updates that are not in the foreground are subject to some limits when running on O devices. Location updates are still available in the background, but they may be happen less frequently than the interval specified in LocationRequest#setInterval. Developers have the following options for getting more frequent location updates:

  1. Request updates in the foreground. This means requesting and removing updates as part of the activity lifecycle (request in onResume() and remove in onPause(), for example). Apps running in the foreground are not subject to any location limits on O devices .

  2. Request updates using a foreground service. This involves displaying a persistent notification to users.

  3. Use geofencing to trigger notifications based on the device’s location. If your use case relies on the device entering, dwelling, or exiting a particular area of interest, this API provides a performant way to get these notifications. See the GeofencingEvent#getTriggeringLocation[, which gets the location that triggered the geofence transition.

  4. Use batched location updates using LocationRequest#setMaxWaitTime. With this API, locations may be provided more frequently than the non-batched API however, will be delivered in a batch after the interval specified in setMaxWaitTime (also limited to a few times an hour) Use passive location updates: While your app is in the background, it may continue to receive location updates passively if another app in the foreground requests location updates. You can receive some of these updates by using LocationRequest#setFastestInterval with a small interval, such as 5 min.

like image 120
Shailen Tuli Avatar answered Dec 08 '25 10:12

Shailen Tuli


Given that this is a large-scoped question on how to handle Android O background location restrictions, this may be relevant:

If your app needs to receive locations in the background primarily to use as a dependent input, Awareness API may be useful for you.

Geofence is one example where you want to be notified when device moves by X miles (and you do not really care about the actual location coordinates). Similarly, if you need location for things like fetching location-dependent data on server, or triggering location-dependent notifications, Awareness has a bunch of useful APIs.

For example, the weather snapshot API lets you get the weather at device location without you having to request locations. TimeFence has APIs for waking-up apps at instants based on timezone or sunrise/set etc at device location.

like image 45
MRC Avatar answered Dec 08 '25 08:12

MRC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!