public interface WearableBridge
Internal service-provider interface implemented by each platform port to carry the
com.codename1.wearable API onto the native phone-to-watch transport (Apple’s WCSession or
Google’s Wearable Data Layer).
Application code never touches this interface – it is obtained by the com.codename1.wearable
framework from com.codename1.ui.Display#getWearableBridge() and driven through the public
com.codename1.wearable.WearableConnection API. The base implementation returns null, which is
why the public API degrades to a harmless no-op on the simulator and on ports with no paired
device (so application code needs no platform if statements).
Payloads cross this interface as the opaque bytes produced by
com.codename1.wearable.WearableMessage#toByteArray(), so a port only has to move bytes and
never has to understand the value model. Incoming traffic is pushed back the other way by calling
the static entry points on com.codename1.wearable.WearableConnection
(deliverMessage, deliverReply, deliverDataChanged, deliverDataRemoved,
notifyStateChanged), which take care of EDT dispatch and of queueing across a cold start.
Methods
public abstract boolean isSupported() | Returns true when the PLATFORM provides the transport and this app may use it – not whether a counterpart device exists. |
public abstract boolean isPaired() | Returns true when a counterpart device is paired with this one, whether or not it is currently switched on or in range. |
public abstract boolean isReachable() | Returns true when the peer app can receive a live message right now. |
public abstract boolean isCompanionAppInstalled() | Returns true when the counterpart app is actually installed on the paired device. |
public abstract String[] getConnectedNodes() | Returns the currently connected counterpart devices, one entry per device, each formatted as id \t displayName \t 1|0 where the trailing flag is whether the device is nearby. |
public abstract void sendMessage(String path, byte[] payload, int replyToken) | Sends a live message to the peer app, delivered only if it is reachable. |
public abstract void sendReply(int replyToken, byte[] payload) | Answers a message the peer sent with a reply token. |
public abstract void putData(String path, byte[] payload) | Publishes or replaces the replicated value at a path. |
public abstract byte[] getData(String path) | Returns the replicated value at a path, as published by either side. |
public abstract void removeData(String path) | Removes the replicated value at a path. |
public abstract String[] getDataPaths() | Returns every path that currently holds a replicated value. |
public abstract void transferFile(String path, String name, byte[] contents) | Transfers a file to the peer in the background. |
Method details
isSupported
public abstract boolean isSupported()Returns true when the PLATFORM provides the transport and this app may use it – not whether a counterpart device exists.
An implementation should answer for the API, not for the pairing: Apple’s bridge reports
WCSession availability whether or not a watch is paired, and an implementation that folded
pairing into this answer would make the whole public API inert on a phone whose watch merely
happens to be unpaired right now. Pairing is isPaired()’s question and reachability is
isReachable()’s.
False makes the whole public API inert, so return false only when there is no transport.
Returns
isPaired
public abstract boolean isPaired()Returns
isReachable
public abstract boolean isReachable()sendMessage needs; replicated data does not.Returns
isCompanionAppInstalled
public abstract boolean isCompanionAppInstalled()Returns
getConnectedNodes
public abstract String[] getConnectedNodes()id \t displayName \t 1|0 where the trailing flag is whether the device is nearby. The flat
string form keeps the interface to primitives so native ports do not have to construct Java
objects.Returns
sendMessage
public abstract void sendMessage(String path, byte[] payload, int replyToken)Parameters
pathString- the path the peer matches on
payloadbyte[]- the encoded payload
replyTokenint- a positive token to answer with
WearableConnection.deliverReplywhen the sender wants a reply, or 0 when it does not
sendReply
public abstract void sendReply(int replyToken, byte[] payload)Parameters
replyTokenint- the token that arrived with the request
payloadbyte[]- the encoded reply payload
putData
public abstract void putData(String path, byte[] payload)Parameters
pathString- the path to publish under
payloadbyte[]- the encoded payload
getData
public abstract byte[] getData(String path)Parameters
pathString- the path to read
Returns
removeData
public abstract void removeData(String path)Parameters
pathString- the path to clear
getDataPaths
public abstract String[] getDataPaths()Returns
transferFile
public abstract void transferFile(String path, String name, byte[] contents)Parameters
pathString- the path the peer matches on
nameString- the file name to present to the peer
contentsbyte[]- the file bytes