public class Beacon extends Object implements Parcelable, Serializable
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)
| Modifier and Type | Class and Description |
|---|---|
static class |
Beacon.Builder
Builder class for Beacon objects.
|
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>| Modifier and Type | Field and Description |
|---|---|
protected static BeaconDataFactory |
beaconDataFactory
Used to attach data to individual Beacons, either locally or in the cloud
|
static Parcelable.Creator<Beacon> |
CREATOR
Deprecated.
|
protected int |
mBeaconTypeCode
The two byte value indicating the type of beacon that this is, which is used for figuring
out the byte layout of the beacon advertisement
|
protected String |
mBluetoothAddress
The Bluetooth mac address
|
protected String |
mBluetoothName
The Bluetooth device name.
|
protected List<Long> |
mDataFields
A list of generic non-identifying data fields included in the beacon advertisement.
|
protected Double |
mDistance
A double that is an estimate of how far the Beacon is away in meters.
|
protected List<Long> |
mExtraDataFields
A list of generic non-identifying data fields included in a secondary beacon advertisement
and merged into this beacon.
|
protected long |
mFirstCycleDetectionTimestamp
The timestamp of the first packet detected in milliseconds.
|
protected List<Identifier> |
mIdentifiers
The a list of the multi-part identifiers of the beacon.
|
protected long |
mLastCycleDetectionTimestamp
The timestamp of the last packet detected in milliseconds.
|
protected int |
mManufacturer
A two byte code indicating the beacon manufacturer.
|
protected boolean |
mMultiFrameBeacon
An indicator marking this beacon as a potential multi frame beacon.
|
protected String |
mParserIdentifier
The identifier of the beaconParser used to create this beacon.
|
protected int |
mRssi
The measured signal strength of the Bluetooth packet that led do this Beacon detection.
|
protected int |
mServiceUuid
A 32 bit service uuid for the beacon
This is valid only for GATT-based beacons.
|
protected int |
mTxPower
The calibrated measured Tx power of the Beacon in RSSI
This value is baked into an Beacon when it is manufactured, and
it is transmitted with each packet to aid in the mDistance estimate
|
protected static DistanceCalculator |
sDistanceCalculator |
protected static boolean |
sHardwareEqualityEnforced
Determines whether a the bluetoothAddress (mac address) must be the same for two Beacons
to be configured equal.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE| Modifier | Constructor and Description |
|---|---|
protected |
Beacon()
Basic constructor that simply allocates fields
|
protected |
Beacon(Beacon otherBeacon)
Copy constructor
|
protected |
Beacon(Parcel in)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
protected static Double |
calculateDistance(int txPower,
double bestRssiAvailable)
Estimate the distance to the beacon using the DistanceCalculator set on this class.
|
int |
describeContents()
Deprecated.
|
boolean |
equals(Object that)
Two detected beacons are considered equal if they share the same three identifiers, regardless of their mDistance or RSSI.
|
int |
getBeaconTypeCode() |
String |
getBluetoothAddress() |
String |
getBluetoothName() |
List<Long> |
getDataFields()
Returns the list of data fields 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.
|
static DistanceCalculator |
getDistanceCalculator()
Gets the DistanceCalculator to use with this beacon
|
List<Long> |
getExtraDataFields()
Returns the list of data fields transmitted with the advertisement
|
long |
getFirstCycleDetectionTimestamp()
Returns the timestamp of the first packet detected
|
static boolean |
getHardwareEqualityEnforced() |
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
|
Identifier |
getIdentifier(int i)
Returns the specified identifier - 0 indexed
Note: to read id1, call getIdentifier(0);
|
List<Identifier> |
getIdentifiers()
Returns the list of identifiers transmitted with the advertisement
|
long |
getLastCycleDetectionTimestamp()
Returns the timestamp of the last packet detected
|
int |
getManufacturer() |
int |
getMeasurementCount()
Returns the number of packet detections that went in to the runningAverageRssi, if known.
|
int |
getPacketCount()
Returns the number of packet detections in the last ranging cycle
|
String |
getParserIdentifier() |
int |
getRssi() |
double |
getRunningAverageRssi()
Returns the running average rssi
|
double |
getRunningAverageRssi(double rssi)
Deprecated.
To be removed in a future release. Use
getRunningAverageRssi()
instead. |
int |
getServiceUuid() |
int |
getTxPower() |
int |
hashCode()
Calculate a hashCode for this beacon
|
boolean |
isExtraBeaconData()
Indicates whether this beacon is an "Extra data beacon," meaning one that has no identifiers
but has data fields.
|
boolean |
isMultiFrameBeacon() |
void |
requestData(BeaconDataNotifier notifier)
Requests server-side data for this beacon.
|
static void |
setDistanceCalculator(DistanceCalculator dc)
Sets the DistanceCalculator to use with this beacon
|
void |
setExtraDataFields(List<Long> fields)
Sets extra data fields
|
void |
setFirstCycleDetectionTimestamp(long firstCycleDetectionTimestamp)
Sets the timestamp of the first packet detected
|
static void |
setHardwareEqualityEnforced(boolean e)
Configures whether a the bluetoothAddress (mac address) must be the same for two Beacons
to be configured equal.
|
void |
setLastCycleDetectionTimestamp(long lastCycleDetectionTimestamp)
Sets the timestamp of the last packet detected
|
void |
setPacketCount(int packetCount)
Sets the packet detections in the last ranging cycle
|
void |
setRssi(int rssi)
Sets the most recently measured rssi for use in distance calculations if a running average is
not available
|
void |
setRssiMeasurementCount(int rssiMeasurementCount)
Sets the measurement count that went into the rssi sample
|
void |
setRunningAverageRssi(double rssi)
Sets the running average rssi for use in distance calculations
|
String |
toString()
Formats a beacon as a string showing only its unique identifiers
|
void |
writeToParcel(Parcel out,
int flags)
Deprecated.
|
protected static boolean sHardwareEqualityEnforced
protected static DistanceCalculator sDistanceCalculator
protected List<Identifier> mIdentifiers
protected List<Long> mDataFields
protected List<Long> mExtraDataFields
protected Double mDistance
protected int mRssi
protected int mTxPower
protected String mBluetoothAddress
protected static BeaconDataFactory beaconDataFactory
protected int mBeaconTypeCode
protected int mManufacturer
protected int mServiceUuid
protected String mBluetoothName
protected String mParserIdentifier
protected boolean mMultiFrameBeacon
protected long mFirstCycleDetectionTimestamp
protected long mLastCycleDetectionTimestamp
@Deprecated public static final Parcelable.Creator<Beacon> CREATOR
@Deprecated protected Beacon(Parcel in)
in - parcelprotected Beacon(Beacon otherBeacon)
otherBeacon - protected Beacon()
public static void setDistanceCalculator(DistanceCalculator dc)
dc - public static DistanceCalculator getDistanceCalculator()
public static void setHardwareEqualityEnforced(boolean e)
e - public static boolean getHardwareEqualityEnforced()
public void setRssiMeasurementCount(int rssiMeasurementCount)
rssiMeasurementCount - public int getPacketCount()
public void setPacketCount(int packetCount)
packetCount - public long getFirstCycleDetectionTimestamp()
public void setFirstCycleDetectionTimestamp(long firstCycleDetectionTimestamp)
firstCycleDetectionTimestamp - public long getLastCycleDetectionTimestamp()
public void setLastCycleDetectionTimestamp(long lastCycleDetectionTimestamp)
lastCycleDetectionTimestamp - public int getMeasurementCount()
public void setRunningAverageRssi(double rssi)
rssi - the running average rssi@Deprecated public double getRunningAverageRssi(double rssi)
getRunningAverageRssi()
instead.public double getRunningAverageRssi()
public void setRssi(int rssi)
rssi - public int getManufacturer()
mManufacturerpublic int getServiceUuid()
mServiceUuidpublic Identifier getIdentifier(int i)
i - - index identfierpublic Identifier getId1()
public Identifier getId2()
public Identifier getId3()
public List<Long> getDataFields()
public List<Long> getExtraDataFields()
public void setExtraDataFields(List<Long> fields)
fields - public List<Identifier> getIdentifiers()
public double getDistance()
mDistancepublic int getRssi()
mRssipublic int getTxPower()
mTxPowerpublic int getBeaconTypeCode()
mBeaconTypeCodepublic String getBluetoothAddress()
mBluetoothAddresspublic String getBluetoothName()
mBluetoothNamepublic String getParserIdentifier()
mParserIdentifierpublic boolean isMultiFrameBeacon()
mMultiFrameBeaconpublic int hashCode()
public boolean equals(Object that)
public void requestData(BeaconDataNotifier notifier)
notifier - interface providing a callback when data are availablepublic String toString()
@Deprecated public int describeContents()
describeContents in interface Parcelable@Deprecated public void writeToParcel(Parcel out, int flags)
writeToParcel in interface Parcelablepublic boolean isExtraBeaconData()
protected static Double calculateDistance(int txPower, double bestRssiAvailable)
txPower - bestRssiAvailable - DistanceCalculator