mcharmas / Android-ReactiveLocation

Small library that wraps Google Play Service API in brilliant RxJava Observables reducing boilerplate to minimum.
2.11k stars 312 forks source link

Oreo background limitations #179

Open carbonaro opened 6 years ago

carbonaro commented 6 years ago

As per https://developer.android.com/about/versions/oreo/background-location-limits.html the FusedLocationProvider's behaviour has been significantly affected on Oreo :

Fused Location Provider (FLP)

If your app is running in the background, the location system service computes a new location for your app only a few times each hour. This is the case even when your app is requesting more frequent location updates.

By using the batched version of FLP, however, you have access to more time-frequent location history after your app receives a batch update, which also occurs only a few times each hour.

If your app is running in the foreground, there is no change in location sampling rates compared to Android 7.1.1 (API level 25).

My app needs to receive more frequent update than that ; the documentation page suggests the following :

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.

Is it possible to implement that with Android-ReactiveLocation ?

lollipierre commented 6 years ago

I was about to raise a similar issue. Oreo limitations when doing location in the background are quite annoying, and I really hope we can continue using this lib :(

cyrixmorten commented 6 years ago

Creating a foreground service to handle location updates is outside the scope of this library in my opinion.

On Dec 27, 2017 18:01, "lollipierre" notifications@github.com wrote:

I was about to raise a similar issue. Oreo limitations when doing location in the background are quite annoying, and I really hope we can continue using this lib :(

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mcharmas/Android-ReactiveLocation/issues/179#issuecomment-354143319, or mute the thread https://github.com/notifications/unsubscribe-auth/AGV5ODPDIAvLQLou1WpwFKDG3R1QNH78ks5tEnf_gaJpZM4RNpt- .

carbonaro commented 6 years ago

Fair enough - how would you go about this? I must admit I am a still a little bit confused about Oreo's changes right now.

cyrixmorten commented 6 years ago

Not at my computer at the moment so cannot post an example of how I did it but there are plenty of examples of how to create a foreground service.

Official documentation here: https://developer.android.com/guide/components/services.html#Foreground

On Dec 27, 2017 18:08, "Philippe Breuils" notifications@github.com wrote:

Fair enough - how would you go about this? I must admit I am a still a little bit confused about Oreo's changes right now.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mcharmas/Android-ReactiveLocation/issues/179#issuecomment-354144302, or mute the thread https://github.com/notifications/unsubscribe-auth/AGV5OJJN6QGLAwmlqNt62RV0VukvqUS7ks5tEnmfgaJpZM4RNpt- .

Lir10 commented 6 years ago

@cyrixmorten @carbonaro Have been tested Activity Recognition with Foreground service and it's working fine on Oreo. i'm guessing it's the same with fusedlocation.

Foreground service is the same logic as regular services you just need to add the notification builder and when you start the service startForegroundService()

carbonaro commented 6 years ago

@cyrixmorten, @Lir10 thanks for the feedback. I'll work on a Foreground service implementation for Activity Recognition.

Shu1111 commented 6 years ago

Have any idea how to keep getting Wi-Fi samples every few minutes in Oreo (without the background service and without the foreground service)?

cyrixmorten commented 6 years ago

Do not think it is possible.

You could create a periodic job with a library such as: https://github.com/evernote/android-job https://github.com/evernote/android-job

However, I believe that you would still need to have a foreground service active to prevent the job from being silently killed by the system: https://github.com/evernote/android-job/issues/350 https://github.com/evernote/android-job/issues/350

Not sure though, so worth a shot.

On 19 Feb 2018, at 15.42, Shu1111 notifications@github.com wrote:

Have any idea how to keep getting Wi-Fi samples every few minutes in Oreo (without the background service and without the foreground service)?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mcharmas/Android-ReactiveLocation/issues/179#issuecomment-366712691, or mute the thread https://github.com/notifications/unsubscribe-auth/AGV5OMhrLFq7FQ68EUNYOhmBcUuwIQEXks5tWYhVgaJpZM4RNpt-.

muradmohdzain commented 6 years ago

creating a Foreground service would be annoying to some users as they will see the notification in the status bar. I also experienced that oreo displayed a wierd behaviour when i turn on the gps compared to nouget. I monitored this in my app widget. In oreo you have to wait a few minutes in order to see the location updates but in nouget the location will updated immediately after you turn on gps. To get the location updates immediately in oreo i have to open the application (what an annoying to do). So how to solve this problem in oreo without opening the application ?