4

I am using the alt.beacon library and now I get this warning:

warning: [deprecation] setRangeNotifier(RangeNotifier) in BeaconManager has been deprecated.

But what is the replacement? I need to range the beacons from a region and the callback RangeNotifier it crucial to implement this feature.

public interface RangeNotifier {
    void didRangeBeaconsInRegion(Collection<Beacon> var1, Region var2);
}

Anyone has a sample of how the new library is supposed to work?

thx!

gmmo
  • 2,577
  • 3
  • 30
  • 56

1 Answers1

8

Starting with version 2.9, you may have more than one RangeNotifier. So instead of calling:

beaconManager.setRangeNotifier(rangeNotifier);

Simply call:

beaconManager.addRangeNotifier(rangeNotifier);
davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • It may be worth noting to call beaconManager.removeAllRangeNotifiers(); prior to adding it again, though it probably is common sense. I am setting the range notifier from a fragment, and this can be added to any activity that needs to monitor beacons. Without clearing the range notifiers, you end up getting a range result for every rangeNotifier you have added, which can amount to a lot when navigating around an app – WallyHale Dec 14 '16 at 00:17
  • The good news is that this should not be necessary. The collection of rangeNotifiers is defined as a Set: ` protected final Set rangeNotifiers = new CopyOnWriteArraySet<>();` so if you add the same notifier multiple times, it should simply replace the one that already exists. – davidgyoung Dec 14 '16 at 04:50
  • Hmmmmm .. that doesn't seem to be the case for me. The same fragment adds itself on various activities. And I found that going from menu (with beacon detection) to activity (with beacon detection) and back again say 5 times, it would result in 5 range triggers every second! The same notifier is used as the code is unchanged, the only difference could be a getActivity reference when I'm displaying the beacon in the UI? Would this change the notifier and make it unique? – WallyHale Dec 14 '16 at 09:34
  • Ah, perhaps the issue is that the fragment is a different object instance each time. In this case, clearing the old notifiers is probably the correct approach. – davidgyoung Dec 14 '16 at 13:09