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.
-
Method Summary
Modifier and TypeMethodDescriptionString[]Returns the currently connected counterpart devices, one entry per device, each formatted asid \t displayName \t 1|0where the trailing flag is whether the device is nearby.byte[]Returns the replicated value at a path, as published by either side.String[]Returns every path that currently holds a replicated value.booleanReturns true when the counterpart app is actually installed on the paired device.booleanisPaired()Returns true when a counterpart device is paired with this one, whether or not it is currently switched on or in range.booleanReturns true when the peer app can receive a live message right now.booleanReturns true when this device can talk to a counterpart at all -- the transport exists and the app is allowed to use it.voidPublishes or replaces the replicated value at a path.voidremoveData(String path) Removes the replicated value at a path.voidsendMessage(String path, byte[] payload, int replyToken) Sends a live message to the peer app, delivered only if it is reachable.voidsendReply(int replyToken, byte[] payload) Answers a message the peer sent with a reply token.voidtransferFile(String path, String name, byte[] contents) Transfers a file to the peer in the background.
-
Method Details
-
isSupported
boolean isSupported()Returns true when this device can talk to a counterpart at all -- the transport exists and the app is allowed to use it. False on a platform with no wearable link, which makes the whole public API inert.
Returns
true if the wearable transport is available
-
isPaired
boolean isPaired()Returns true when a counterpart device is paired with this one, whether or not it is currently switched on or in range.
Returns
true if a counterpart device is paired
-
isReachable
boolean isReachable()Returns true when the peer app can receive a live message right now. This is the condition
sendMessageneeds; replicated data does not.Returns
true if the peer app is reachable
-
isCompanionAppInstalled
boolean isCompanionAppInstalled()Returns true when the counterpart app is actually installed on the paired device. A paired watch with no watch app installed is the common case worth telling the user about.
Returns
true if the peer app is installed
-
getConnectedNodes
String[] getConnectedNodes()Returns the currently connected counterpart devices, one entry per device, each formatted as
id \t displayName \t 1|0where 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
the connected nodes, never null; an empty array when nothing is connected
-
sendMessage
Sends a live message to the peer app, delivered only if it is reachable.
Parameters
path: the path the peer matches onpayload: the encoded payloadreplyToken: a positive token to answer withWearableConnection.deliverReplywhen the sender wants a reply, or 0 when it does not
-
sendReply
void sendReply(int replyToken, byte[] payload) Answers a message the peer sent with a reply token.
Parameters
replyToken: the token that arrived with the requestpayload: the encoded reply payload
-
putData
Publishes or replaces the replicated value at a path. The value must survive this app being killed and must reach the peer whenever it next runs.
Parameters
path: the path to publish underpayload: the encoded payload
-
getData
Returns the replicated value at a path, as published by either side.
Parameters
path: the path to read
Returns
the encoded payload, or null when nothing is published at that path
-
removeData
Removes the replicated value at a path.
Parameters
path: the path to clear
-
getDataPaths
String[] getDataPaths()Returns every path that currently holds a replicated value.
Returns
the published paths, never null
-
transferFile
Transfers a file to the peer in the background. Delivery may happen long after this returns, including after this app has exited.
Parameters
path: the path the peer matches onname: the file name to present to the peercontents: the file bytes
-