Skip to content Skip to sidebar Skip to footer

Google Nearby Api Background Scan Doesn´t Work After Application Kill

I have kontakt.io beacon and I try to write application for background scanning with nearby API. I use this method to subscribe messages: SubscribeOptions options = new SubscribeO

Solution 1:

Haven't really tried using one yet, but have you considered/checked on using a Service? As per the description:

A service can essentially take two forms:

Started

A service is "started" when an application component (such as an activity) starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. Usually, a started service performs a single operation and does not return a result to the caller. For example, it might download or upload a file over the network. When the operation is done, the service should stop itself.

Bound

A service is "bound" when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed.

You could create a Service that runs the scan continuously until such time that you choose to stop/destroy it. The docs itself already has step on Creating a Started Service. Just read it thoroughly.

Solution 2:

There are two ways to kill an app. If you find the app in Settings > Apps and press "Force Stop", or equivalently if you run adb shell am force-stop <package>, that kills the Nearby subscription too. But if you kill the app by swiping it away in the recents view, or by using adb shell kill <process-id>, the Nearby subscription should stay alive and wake your app with a PendingIntent.

Post a Comment for "Google Nearby Api Background Scan Doesn´t Work After Application Kill"