0

Recently I started playing with a few Kontakt beacons and my Android phone (LG L30).

I added a default region to detect all beacons:

private static final Region ALL_BEACONS_REGION = Region.EVERYWHERE;

And I initialized a new monitoringListener. The relevant code:

    @Override
    public void onBeaconsUpdated(Region region, List<BeaconDevice> list) {
       List<BeaconDevice> beacons = new ArrayList<BeaconDevice>();
       Iterator i = list.iterator();
       while (i.hasNext()){
           BeaconDevice beacon = (BeaconDevice)i.next();
           if(beacon.getUniqueId() != null) {
               beacons.add(beacon);
           }
        }    
  }

While debugging I noticed, that sometimes the uniqueId is null. That's why I am checking if it is null, but I still find it very strange. Is that common or is there a mistake in my code? And how can I uniquely identify a beacon if the name is null?

Ziga Petek
  • 3,953
  • 5
  • 33
  • 43

1 Answers1

0

Hmm to check why getUniqueId() return NULL, we must see how you set this value.

An object you can identify uniquely by using his hashCode(). Override this method in the object to generate something uniquely.
see: overriding equals and hashCode in Java

Or if you want only prevent multiple-entries in the list, you could us a Set, which not add duplicates (compared to the your ArrayList). see: Java - Set

Community
  • 1
  • 1
JoGe
  • 872
  • 10
  • 26
  • Yes, that would be one option. – Ziga Petek Jul 26 '15 at 12:01
  • 1
    Yes, that would be one option. I don't like looking into the source code of an API, but this time I guess it was a necessity. The uniqueId is part of the advertising package of a beacon and therefore the Android API reads it from the array of bytes it gets, when it gets the advertisement of a beacon. I guess it is a possibility, that the advertisement the device gets is not complete due to signal disturbances, but I rather be sure. I'll keep the question open in case a beacon expert sees it and has an answer. – Ziga Petek Jul 26 '15 at 12:06