Milan Sheth
Milan Sheth

Reputation: 972

Continuous android location background from Android OS 8 or higher

I am trying to fetch user exact location by running a location service in background but onLocationChanged event only triggers when app is in foreground. As soon as app goes background or killed my location services doesn't trigger onLocationChanged event from service due to which I am unable to get user exact location.

I am using FusedLocationProviderClient API in my location service. As per https://developer.android.com/training/location/background there are some limitation on location background. Where in document it was saying itself:

If background location access is essential for your app, keep in mind that Android preserves device battery life by setting background location limits on devices that run Android 8.0 (API level 26) and higher. On these versions of Android, if your app is running in the background, it can receive location updates only a few times each hour.

Please help me to achieve my functionality. Any guideline / help / code sample / link / hint would be great appreciate.

Upvotes: 0

Views: 288

Answers (1)

Arno den Hond
Arno den Hond

Reputation: 627

Start a foreground service in your app by calling startForegroundService(). When such a foreground service is active, it appears as an ongoing notification in the notification area.

Upvotes: 1

Related Questions