Skip to content

Commit

Permalink
support beacons without name
Browse files Browse the repository at this point in the history
fixes #22
  • Loading branch information
ostrya committed Sep 6, 2020
1 parent eeef0d0 commit a0a5420
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,23 @@ private class ScanCallback implements RangeNotifier {
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
HyperLog.v(TAG, "Got callback from beacon scan for region " + region);
for (Beacon beacon : beacons) {
if (beacon != null) {
if (beacon.getBluetoothName() != null && beacon.getBluetoothAddress() != null) {
HyperLog.d(TAG, "Found beacon " + beacon);
adapter.addBeacon(beacon);
} else {
HyperLog.d(TAG, "Beacon " + beacon + " is incomplete: " + beacon.getBluetoothName() + "/" + beacon.getBluetoothAddress());
}
if (beacon != null && beacon.getBluetoothAddress() != null) {
HyperLog.d(TAG, "Found beacon " + beacon);
adapter.addBeacon(fixEmptyName(beacon));
} else {
HyperLog.w(TAG, "Beacon " + beacon + " does not have a Bluetooth address");
}
}
}

private Beacon fixEmptyName(Beacon beacon) {
if (beacon.getBluetoothName() != null) {
return beacon;
}
return new Beacon.Builder()
.copyBeaconFields(beacon)
.setBluetoothName(beacon.getBluetoothAddress())
.build();
}
}
}

0 comments on commit a0a5420

Please sign in to comment.