In case of Android version prior 8.0 (Oreo) - there is no supported way to keep scans working while application itself is not running. This is how Android security/power-management is designed and we cannot do anything about it.
However, we have to clarify what does exactly mean āApplication is killedā
Basically - killed application is a state when the process hosting application content is not running. Killed application IS NOT the state when just the activity was destroyed. In other words - it is possible to exit the application (kill the activity) but still keep the background process up-and running with active scan in place.
To achieve such behaviour with Proximity-SDK, you need to use withScannerInForegroundService option when creating ProximityObserver instance. Here is Kotlin example:
With ProximityObserver created in such way, each scan will be performed within foreground service (Check out more information about foreground services here). This will allow us to continue scanning even if main application is no longer visible for the user.
Thanks for your reply
What I had meant by āapplication is killedā was that it had been dismissed or swiped up etc from the android multitasking application tray.
So is there no work around for now to actually keep the scanner running in the background with the foreground notification??
What i really wanted to do was just:
If the bluetooth is on please look for estimote bluetooth devices (regardless of having the application open in the foreground or is minimised into background (is active in the multitasking app tray)
If it is in the vicinity then have the phone display the notification.
From what i understand from your response is that this is not achieve able on any android version prior to android 8?
I think i wasnāt crystal clear when I elaborated about āapplication is killedā and handling this situation in different Android versions term
Once again:
Application is killed when process hosting this application is no longer running (e.g. you killed application by going to Setting->Applications-> and choosing āKill Appā option). In such case - there are options to continue scanning only on Android 8+. However - this is not your cace
Application is NOT Killed when you just swipe out its Activity, press home button etc. In such case we are able to continue scan on all supported Android version. I believe this is exactly your case
To continue scanning while application is in background (not running from user perspective) you have to use withScannerInForegroundService option when creating proximity observer.
As a result, our SDK will pop up notification in Androidās status bar and thus become āforeground oneā even if user destroy applicationās activity.
You probably know this behaviour from other applications abe to work in background while user interacts with different stuff. Spotify is a good example - when it starts to play, then notification appears in status bar and you can easily āexitā the Spotifyās activity and still listen the song.
Great explanation - I believe weāre getting on to the same page now
I also have implemented the foreground service with my scanner but when the app is slided up from the multitasking - it just kills my scanner.
What I am trying to do is that; I want to be able to scan for Estimote beacons without having to open the app and leaving in the background.
Sort of like how messaging apps when you restart the phone and it isnāt running itāll get get messages sent kinda thing.
Is this possible? Hope Iāve some what clarify my actual question
Iām sorry for delayed response - Iāve been super busy last days.
Regarding messaging-like behaviour - Unfortunately I think youāll not be able to achieve it with BLE technology. This is because messaging application (like hangouts, facebook messenger etc.) utilizes Firebase Cloud Messaging infrastructure to get launched/notified whenever new message arrives. Firebase ensures that each registered application will get notified (or even launched when itās not running) whenever new message pop up for this app. Unfortunately Android does not support similar mechanisms for BLE scanning. All you can do is to fire up your scan in foreground service with notification icon in notification bar. - This is exactly what our SDK is doing when withScannerInForegroundService(...) option is used during proximityObserver construction.
First, I think you should know what exactly happens to running services when app is swiped away from the recent app list in Android and then make the Android service keep running even after app swipe. I have written a detailed post on this on medium and you may check it .