Estimote / Android-Fleet-Management-SDK

Estimote Fleet Management SDK for Android
https://developer.estimote.com
MIT License
836 stars 451 forks source link

Background monitoring not working in Android O (8.0.0 DP3) #234

Closed andreasfranz closed 7 years ago

andreasfranz commented 7 years ago

Phone Model: Nexus 5X Android Version: Android 8.0.0 Developer Preview 3 Estimote SDK version: 1.0.3:release

I us the example project from the Android tutorial (http://developer.estimote.com/android/tutorial/estimote-android-tutorial-ea99e83c.zip). After starting the app and putting it in the background it takes around 30s until I get the following stack trace:

07-03 09:49:47.501 27758-27758/com.example.airport E/AndroidRuntime:
FATAL EXCEPTION: main
     Process: com.example.airport, PID: 27758
     java.lang.RuntimeException: Unable to start receiver com.estimote.coresdk.scanning.scheduling.SystemAlarmManager$AlarmBroadcastReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.example.airport/com.estimote.coresdk.service.BeaconService }: app is in background uid UidRecord{c3a4177 u0a155 RCVR bg:+1m13s10ms idle procs:1 seq(0,0,0)}
         at android.app.ActivityThread.handleReceiver(ActivityThread.java:3259)
         at android.app.ActivityThread.-wrap17(Unknown Source:0)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
         at android.os.Handler.dispatchMessage(Handler.java:105)
         at android.os.Looper.loop(Looper.java:164)
         at android.app.ActivityThread.main(ActivityThread.java:6541)
         at java.lang.reflect.Method.invoke(Native Method)
         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
      Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.example.airport/com.estimote.coresdk.service.BeaconService }: app is in background uid UidRecord{c3a4177 u0a155 RCVR bg:+1m13s10ms idle procs:1 seq(0,0,0)}
         at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1499)
         at android.app.ContextImpl.startService(ContextImpl.java:1455)
         at android.content.ContextWrapper.startService(ContextWrapper.java:644)
         at android.content.ContextWrapper.startService(ContextWrapper.java:644)
         at com.estimote.coresdk.scanning.scheduling.SystemAlarmManager$AlarmBroadcastReceiver.onReceive(SystemAlarmManager.java:51)
         at android.app.ActivityThread.handleReceiver(ActivityThread.java:3252)
         at android.app.ActivityThread.-wrap17(Unknown Source:0) 
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677) 
         at android.os.Handler.dispatchMessage(Handler.java:105) 
         at android.os.Looper.loop(Looper.java:164) 
         at android.app.ActivityThread.main(ActivityThread.java:6541) 
         at java.lang.reflect.Method.invoke(Native Method) 
         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)  

Probably the issue could be related to the new background service restrictions that are introduced with Android O (https://developer.android.com/preview/features/background.html#services).

pawelDylag commented 7 years ago

Hey @andreasfranz

Yes, this is due to new Android O restrictions. We are planning to add support for Android O in upcoming weeks. Stay tuned!

jonasborggren commented 7 years ago

What workaround did you use for this problem?

andreasfranz commented 7 years ago

No workaround so far.

ericksprengel commented 7 years ago

Replace the Service by a JobScheduler.

cbadhrinath commented 7 years ago

@pawelDylag Just looked into the source code of the latest Estimote 1.2.0 library and looks like this BeaconService issue is fixed with an Alarm Manager. Works fine in background mode (Tested on Pixel with Android O). Should this issue be closed, or is there any other known issue. Please let me know. Thanks.

pawelDylag commented 7 years ago

Hey guys,

Just to let you know - we are working on a refreshed version of our SDK. It is designed to take advantage of all the new possibilities that Android N/O gives us. We know that the current version is not fully supporting those platforms and we are aware of some problems with scanning (time, battery drain, low reliability). We won't do any quick fixups now, because it's not the proper way we want to handle this. Instead we are working on fully tested, data-driven approach that will give you the best results on recent versions of Android. I'm not allowed to tell you anything more, and I'm also not allowed to tell you that estimated release date is the end of the September ;) Stay tuned!

pawelDylag commented 7 years ago

Hey! I just wanted you to know that we are in the process of moving our SDK for Android to a completely new architecture. We won't be publishing any updates to our old (current master) SDK for a while.

But don't worry - there is an ALPHA version of our FRESH PROXIMITY SDK available now! It uses a completely new scanning mechanism and will work on new Android versions like a charm (6.0, 7.0, 8.0). We did a great job with renovating our ecosystem to cut off the old, messy code, full of hacks for Android KitKat an Jellybean. This is why working with BeaconManager was so frustrating by the way.

Plan for the next couple of weeks:

  1. ProximitySDK beta release - our own tag-based proximity. Use it to achieve the same behaviour as using iBeacon (monitoring/ranging). It is uses our own packets called Estimote Location and is backed-up by our own data-science. Read more here -> http://blog.estimote.com/post/166007374930/the-most-reliable-proximity-tech-now-with-a
  2. ScanningSDK beta release - a separate core library dedicated for raw scanning - it will handle the scanning on all android versions for you, battery efficiency, background/foreground, and will deliver raw stream of packet data (Such as iBeacon, Eddystone, EstimoteLocation, EstimoteTelemetry, etc).

I encourage you to try it out - there is a ready made app for you to show the possibilities of our completely new SDK -> https://github.com/Estimote/Android-SDK/tree/proximity-sdk Let us know what you think! I will keep you updated about the progress.