-3

I am working on Nearby Message API to start a service in my App in he background whenever Eddystone beacon detected nearby.

It works fine but what I observed is that it trigger its onFound event every time I restart Bluetooth.

But I want to trigger onFound event every time I(android device) comes in the range of a beacon(Bluetooth would always be in On Mode).

After debugging, I found that this happens because onLost event not triggered when I go out the range of my beacon, instead, onLost only triggered when I turn-off Bluetooth.

So my Question is, what is the expected behavior of onLost event, and is it possible what I am thinking?

Thanks in advance for your views.

J.Vikas
  • 15
  • 3

2 Answers2

0

From: https://developers.google.com/android/reference/com/google/android/gms/nearby/messages/MessageListener

public void onLost (Message message)

Called when a message is no longer detectable nearby. Note: This callback currently works best for messages attached to BLE beacons. For other messages, it may not be called in a timely fashion, or at all. This method will not be called repeatedly (unless the message is found again between lost calls).

you should try to move away from (or turn off) the beacon and this should trigger "onLost", like turning off Bluetooth

FrancescoR
  • 520
  • 1
  • 4
  • 12
  • Thanks for your response. Actually it was not working because Nearby Message API in Background mode works only after screen-on event. Now I am finding some other way to do so( Without screen-on event). Please suggest any other way if you have implemented so far. – J.Vikas Sep 06 '16 at 07:29
0

The onLost callback is triggered when Nearby scan cannot detect beacon for at least 10 seconds (timeout based on experience, I did not find any official value).

The situation is easy in case of foreground scanning. The scanning is active all the time and Nearby is able to detect "missing" beacon after 10 seconds.

The situation gets complicated in case of background scanning. The scan is performed only on screen-on events so the onLost can be triggered much much later.

I think switching Bluetooth off triggers Nearby and previously found beacons become lost. That's the reason why you get onLost when you switch off Bluetooth. If you are using background scanning, you will get updates when other application makes scan. So if you get out of beacon's range, wait 10 secs and then perform scan by other app, you should get onLost callback.

The same applies to onFound.

I guess it does not solve your problem but hopefully it answers your question...

Dietatko
  • 374
  • 1
  • 13