public final class CompanionDevice
- Object
- CompanionDevice
A device this app is associated with.
An association outlives the app: it is stored by the OS, survives
restarts, and is what makes background presence notifications and
permission-free scanning possible. It ends when the app calls
CompanionDevices.disassociate, when the user revokes it in system
settings, or when the app is uninstalled.
Constructors
public CompanionDevice(String id, String displayName, String address, CompanionProfile profile, boolean present) | Ports construct these; application code reads them from CompanionDevices. |
Methods
public String getId() | The association id, stable across app restarts. |
public String getDisplayName() | The name to show a user. |
public String getAddress() | The device address, or null where the platform does not hand it out. |
public CompanionProfile getProfile() | The profile this association was made under. |
public boolean isPresent() | Whether the device was in range when this record was produced. |
public boolean equals(Object o) | Indicates whether some other object is “equal to” this one. |
public int hashCode() | Returns a hash code value for the object. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Constructor details
CompanionDevice
public CompanionDevice(String id, String displayName, String address, CompanionProfile profile, boolean present)CompanionDevices.Parameters
idString- the platform’s association id
displayNameString- the name to show a user, never null
addressString- the device address, or null when the platform withholds it
profileCompanionProfile- the profile the association was made under
presentboolean- whether the device is in range right now
Method details
getId
public String getId()CompanionDevices.disassociate and
CompanionDevices.startObservingPresence take, and what to persist.getDisplayName
public String getDisplayName()getAddress
public String getAddress()The device address, or null where the platform does not hand it
out. Where it is present it matches
com.codename1.bluetooth.BluetoothDevice#getAddress(), so it can be
passed to BluetoothLE.getPeripheral(String) to open a GATT
connection to the associated device.
Android returns the MAC address for a Bluetooth association. iOS returns the per-app accessory identifier.
getProfile
public CompanionProfile getProfile()isPresent
public boolean isPresent()Whether the device was in range when this record was produced.
This is a snapshot, not a live value – re-read it from
CompanionDevices.getAssociations(), or watch
PresenceListener for changes. Platforms that do not track presence
report false.
equals
public boolean equals(Object o)hashCode
public int hashCode()toString
public String toString()