Google nearby API background scan doesn´t work after application kill

后端 未结 2 788
独厮守ぢ
独厮守ぢ 2021-01-06 02:59

I have kontakt.io beacon and I try to write application for background scanning with nearby API.

I use this method to subscribe messages:

SubscribeO         


        
相关标签:
2条回答
  • 2021-01-06 03:03

    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.

    Hope this helps somehow. Good luck.

    0 讨论(0)
  • 2021-01-06 03:22

    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.

    0 讨论(0)
提交回复
热议问题