-
- All Implemented Interfaces:
-
android.os.Parcelable
,java.io.Serializable
public class Beacon implements Parcelable, Serializable
The
Beacon
class represents a single hardware Beacon detected by an Android device.A Beacon is identified by a unique multi-part identifier, with the first of the ordered identifiers being more significant for the purposes of grouping beacons. A Beacon sends a Bluetooth Low Energy (BLE) advertisement that contains these three identifiers, along with the calibrated tx power (in RSSI) of the Beacon's Bluetooth transmitter. This class may only be instantiated from a BLE packet, and an RSSI measurement for the packet. The class parses out the identifier, along with the calibrated tx power. It then uses the measured RSSI and calibrated tx power to do a rough distance measurement (the mDistance field)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
Beacon.Builder
Builder class for Beacon objects. Provides a convenient way to set the various fields of a Beacon
Example:
Beacon beacon = new Beacon.Builder() .setId1("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6") .setId2("1") .setId3("2") .build();
-
Field Summary
Fields Modifier and Type Field Description public final static Parcelable.Creator<Beacon>
CREATOR
-
Method Summary
Modifier and Type Method Description static void
setDistanceCalculator(DistanceCalculator dc)
Sets the DistanceCalculator to use with this beacon static DistanceCalculator
getDistanceCalculator()
Gets the DistanceCalculator to use with this beacon static void
setHardwareEqualityEnforced(boolean e)
Configures whether a the bluetoothAddress (mac address) must be the same for two Beacons to be configured equal. static boolean
getHardwareEqualityEnforced()
void
setRssiMeasurementCount(int rssiMeasurementCount)
Sets the measurement count that went into the rssi sample int
getPacketCount()
Returns the number of packet detections in the last ranging cycle void
setPacketCount(int packetCount)
Sets the packet detections in the last ranging cycle long
getFirstCycleDetectionTimestamp()
Returns the timestamp of the first packet detected void
setFirstCycleDetectionTimestamp(long firstCycleDetectionTimestamp)
Sets the timestamp of the first packet detected long
getLastCycleDetectionTimestamp()
Returns the timestamp of the last packet detected void
setLastCycleDetectionTimestamp(long lastCycleDetectionTimestamp)
Sets the timestamp of the last packet detected int
getMeasurementCount()
Returns the number of packet detections that went in to the runningAverageRssi, if known. void
setRunningAverageRssi(double rssi)
Sets the running average rssi for use in distance calculations double
getRunningAverageRssi(double rssi)
double
getRunningAverageRssi()
Returns the running average rssi void
setRssi(int rssi)
Sets the most recently measured rssi for use in distance calculations if a running average is not available int
getManufacturer()
int
getServiceUuid()
Array<byte>
getServiceUuid128Bit()
Identifier
getIdentifier(int i)
Returns the specified identifier - 0 indexed Note: to read id1, call getIdentifier(0); Identifier
getId1()
Convenience method to get the first identifier Identifier
getId2()
Convenience method to get the second identifier Identifier
getId3()
Convenience method to get the third identifier List<Long>
getDataFields()
Returns the list of data fields transmitted with the advertisement List<Long>
getExtraDataFields()
Returns the list of data fields transmitted with the advertisement void
setExtraDataFields(List<Long> fields)
Sets extra data fields List<Identifier>
getIdentifiers()
Returns the list of identifiers transmitted with the advertisement double
getDistance()
Provides a calculated estimate of the distance to the beacon based on a running average of the RSSI and the transmitted power calibration value included in the beacon advertisement. int
getRssi()
int
getTxPower()
int
getBeaconTypeCode()
String
getBluetoothAddress()
String
getBluetoothName()
String
getParserIdentifier()
boolean
isMultiFrameBeacon()
int
hashCode()
Calculate a hashCode for this beacon boolean
equals(Object that)
Two detected beacons are considered equal if they share the same three identifiers, regardless of their mDistance or RSSI. void
requestData(BeaconDataNotifier notifier)
Requests server-side data for this beacon. String
toString()
Formats a beacon as a string showing only its unique identifiers int
describeContents()
Required for making object Parcelable void
writeToParcel(Parcel out, int flags)
Required for making object Parcelable. boolean
isExtraBeaconData()
Indicates whether this beacon is an "Extra data beacon," meaning one that has no identifiers but has data fields. -
-
Method Detail
-
setDistanceCalculator
static void setDistanceCalculator(DistanceCalculator dc)
Sets the DistanceCalculator to use with this beacon
-
getDistanceCalculator
static DistanceCalculator getDistanceCalculator()
Gets the DistanceCalculator to use with this beacon
-
setHardwareEqualityEnforced
static void setHardwareEqualityEnforced(boolean e)
Configures whether a the bluetoothAddress (mac address) must be the same for two Beacons to be configured equal. This setting applies to all beacon instances in the same process. Defaults to false for backward compatibility.
-
getHardwareEqualityEnforced
static boolean getHardwareEqualityEnforced()
-
setRssiMeasurementCount
void setRssiMeasurementCount(int rssiMeasurementCount)
Sets the measurement count that went into the rssi sample
-
getPacketCount
int getPacketCount()
Returns the number of packet detections in the last ranging cycle
-
setPacketCount
void setPacketCount(int packetCount)
Sets the packet detections in the last ranging cycle
-
getFirstCycleDetectionTimestamp
long getFirstCycleDetectionTimestamp()
Returns the timestamp of the first packet detected
-
setFirstCycleDetectionTimestamp
void setFirstCycleDetectionTimestamp(long firstCycleDetectionTimestamp)
Sets the timestamp of the first packet detected
-
getLastCycleDetectionTimestamp
long getLastCycleDetectionTimestamp()
Returns the timestamp of the last packet detected
-
setLastCycleDetectionTimestamp
void setLastCycleDetectionTimestamp(long lastCycleDetectionTimestamp)
Sets the timestamp of the last packet detected
-
getMeasurementCount
int getMeasurementCount()
Returns the number of packet detections that went in to the runningAverageRssi, if known. If not known or inapplicable for the rssi filter used, this is zero.
-
setRunningAverageRssi
void setRunningAverageRssi(double rssi)
Sets the running average rssi for use in distance calculations
- Parameters:
rssi
- the running average rssi
-
getRunningAverageRssi
@Deprecated() double getRunningAverageRssi(double rssi)
-
getRunningAverageRssi
double getRunningAverageRssi()
Returns the running average rssi
-
setRssi
void setRssi(int rssi)
Sets the most recently measured rssi for use in distance calculations if a running average is not available
-
getManufacturer
int getManufacturer()
-
getServiceUuid
int getServiceUuid()
-
getServiceUuid128Bit
Array<byte> getServiceUuid128Bit()
-
getIdentifier
Identifier getIdentifier(int i)
Returns the specified identifier - 0 indexed Note: to read id1, call getIdentifier(0);
- Parameters:
i
- - index identfier
-
getId1
Identifier getId1()
Convenience method to get the first identifier
-
getId2
Identifier getId2()
Convenience method to get the second identifier
-
getId3
Identifier getId3()
Convenience method to get the third identifier
-
getDataFields
List<Long> getDataFields()
Returns the list of data fields transmitted with the advertisement
-
getExtraDataFields
List<Long> getExtraDataFields()
Returns the list of data fields transmitted with the advertisement
-
setExtraDataFields
void setExtraDataFields(List<Long> fields)
Sets extra data fields
-
getIdentifiers
List<Identifier> getIdentifiers()
Returns the list of identifiers transmitted with the advertisement
-
getDistance
double getDistance()
Provides a calculated estimate of the distance to the beacon based on a running average of the RSSI and the transmitted power calibration value included in the beacon advertisement. This value is specific to the type of Android device receiving the transmission.
-
getRssi
int getRssi()
-
getTxPower
int getTxPower()
-
getBeaconTypeCode
int getBeaconTypeCode()
-
getBluetoothAddress
String getBluetoothAddress()
-
getBluetoothName
String getBluetoothName()
-
getParserIdentifier
String getParserIdentifier()
-
isMultiFrameBeacon
boolean isMultiFrameBeacon()
-
hashCode
int hashCode()
Calculate a hashCode for this beacon
-
equals
boolean equals(Object that)
Two detected beacons are considered equal if they share the same three identifiers, regardless of their mDistance or RSSI.
-
requestData
void requestData(BeaconDataNotifier notifier)
Requests server-side data for this beacon. Requires that a BeaconDataFactory be set up with a backend service.
- Parameters:
notifier
- interface providing a callback when data are available
-
describeContents
@Deprecated() int describeContents()
Required for making object Parcelable
-
writeToParcel
@Deprecated() void writeToParcel(Parcel out, int flags)
Required for making object Parcelable. If you override this class, you must override this method if you add any additional fields.
-
isExtraBeaconData
boolean isExtraBeaconData()
Indicates whether this beacon is an "Extra data beacon," meaning one that has no identifiers but has data fields.
-
-
-
-