public final class RangingToken
- Object
- RangingToken
The handle one device publishes so another can range against it.
A token is opaque and platform-specific. On iOS it wraps an archived
NIDiscoveryToken; on Android it carries the controller’s UWB address,
complex channel, session id and session key. There is no cross-platform
UWB ranging on either OS, so a token is never portable between them –
fromByteArray rejects a token minted by a different platform with a
clear failure rather than handing garbage to a native call.
What the token is for is the out-of-band exchange both platforms
require: prepare a session, publish toByteArray() over some other
channel the two devices already share – a GATT characteristic from
com.codename1.bluetooth is the usual one – and feed what comes back
into RangingSession.start.
byte[] mine = session.getLocalToken().toByteArray();
characteristic.writeValue(mine);
// ... later, when the peer's token arrives ...
session.start(RangingToken.fromByteArray(theirs));
Fields
public static final int PLATFORM_APPLE_NI = 1 | Token minted by Apple’s Nearby Interaction, wrapping an archived NIDiscoveryToken. |
public static final int PLATFORM_ANDROID_UWB = 2 | Token minted by the Android UWB stack, carrying address, channel, session id and key. |
public static final int PLATFORM_SIMULATED = 3 | Token minted by the simulated implementation used on the desktop ports, the simulator and the JavaScript port. |
Methods
public static RangingToken forUwbAddress(byte[] address, int channel, int preambleIndex, int sessionId, byte[] sessionKey) | Builds an Android-shaped token from parameters a third-party UWB accessory reported out of band. |
public static RangingToken fromByteArray(byte[] data) | Rebuilds a token from the bytes toByteArray() produced, typically after they travelled to this device over Bluetooth. |
public byte[] toByteArray() | The encoded form to hand to the peer. |
public int getPlatform() | Which platform minted this token – one of PLATFORM_APPLE_NI, PLATFORM_ANDROID_UWB or PLATFORM_SIMULATED. |
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
Field details
PLATFORM_APPLE_NI
public static final int PLATFORM_APPLE_NI = 1NIDiscoveryToken.PLATFORM_ANDROID_UWB
public static final int PLATFORM_ANDROID_UWB = 2PLATFORM_SIMULATED
public static final int PLATFORM_SIMULATED = 3Method details
forUwbAddress
public static RangingToken forUwbAddress(byte[] address, int channel, int preambleIndex, int sessionId, byte[] sessionKey)Builds an Android-shaped token from parameters a third-party UWB accessory reported out of band.
Android has no equivalent of Apple’s Nearby Interaction Accessory
Protocol, so an accessory there simply tells the phone which channel
and session to join and the phone joins it – that is what this
builds. On iOS, use RangingSession.startAccessory with the
accessory’s configuration data instead; a token built here is
rejected there.
Parameters
addressbyte[]- the accessory’s UWB MAC address, 2 or 8 bytes
channelint- the UWB channel number
preambleIndexint- the preamble index that goes with the channel
sessionIdint- the session id both ends agreed on
sessionKeybyte[]- the session key, or
nullfor an unprovisioned session
Returns
RangingSession.start accepts on AndroidfromByteArray
public static RangingToken fromByteArray(byte[] data)toByteArray() produced, typically
after they travelled to this device over Bluetooth.Parameters
databyte[]- the encoded token
Returns
Throws
IllegalArgumentException- if the bytes are not a Codename One ranging token, or carry a version this build does not understand
toByteArray
public byte[] toByteArray()Returns
getPlatform
public int getPlatform()PLATFORM_APPLE_NI,
PLATFORM_ANDROID_UWB or PLATFORM_SIMULATED. Useful for telling
the user that the device they are pointing at is the wrong kind,
rather than letting the session fail with
NearbyError.INVALID_TOKEN.equals
public boolean equals(Object o)hashCode
public int hashCode()toString
public String toString()