implements DataApi.DataListener MessageApi.MessageListener NodeClient.OnNodeMigratedListener CapabilityApi.CapabilityListener ChannelApi.ChannelListener MessageClient.RpcService
Receives events from other nodes, such as data changes, messages or connectivity events.
The life-cycle of this service is managed by Android Wear. This service will be bound to and events delivered as a result of various Android Wear events, including data, messages and events indicating a device has connected or disconnected from the Android Wear network.
Applications expecting to be notified of events while in the background should extend this
class. Activities and other short-lived Android components may use
DataClient.addListener(DataClient.OnDataChangedListener)
,
MessageClient.addListener(MessageClient.OnMessageReceivedListener)
to receive
events for a limited period of time.
Implementors could use a LocalBroadcastManager
to dispatch events to other components in an application.
For best performance, limit the number of listeners and use mutually exclusive filters where there are multiple listeners. A common pattern is to use prefix filters to listen to different namespaces within an application.
Example manifest entry:
android:pathPrefix is optional.
<service android:name=".MyWearableListenerService" > <intent-filter> <!-- listeners receive events that match the action and data filters --> <action android:name="com.google.android.gms.wearable.DATA_CHANGED" /> <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" /> <action android:name="com.google.android.gms.wearable.REQUEST_RECEIVED" /> <action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" /> <action android:name="com.google.android.gms.wearable.CHANNEL_EVENT" /> <data android:scheme="wear" android:host="*" android:pathPrefix="/prefix" /> </intent-filter> </service>
Inherited Constant Summary
Public Constructor Summary
Public Method Summary
Looper |
getLooper()
This method is used to retrieve the looper all callbacks will run on.
|
final IBinder | |
void |
onCapabilityChanged(CapabilityInfo
capabilityInfo)
|
void |
onChannelClosed(Channel
channel, int closeReason, int appSpecificErrorCode)
Called when a channel is closed.
|
void |
onChannelClosed(ChannelClient.Channel
channel, int closeReason, int appSpecificErrorCode)
Called when a channel is closed.
|
void | |
void |
onChannelOpened(ChannelClient.Channel
channel)
Called when a new channel is opened by a remote node.
|
void | |
void |
onCreate()
|
void | |
void | |
void |
onInputClosed(Channel
channel, int closeReason, int appSpecificErrorCode)
Called when the input side of a channel is closed.
|
void |
onInputClosed(ChannelClient.Channel
channel, int closeReason, int appSpecificErrorCode)
Called when the input side of a channel is closed.
|
void | |
void |
onNodeMigrated(String nodeId,
DataItemBuffer
archive)
Receives notification for migration events when a device switches to a new
network.
|
void |
onOutputClosed(Channel
channel, int closeReason, int appSpecificErrorCode)
Called when the output side of a channel is closed.
|
void |
onOutputClosed(ChannelClient.Channel
channel, int closeReason, int appSpecificErrorCode)
Called when the output side of a channel is closed.
|
void |
onPeerConnected(Node peer)
|
void |
onPeerDisconnected(Node peer)
|
Task<byte[]> |
Inherited Method Summary
Public Constructors
public WearableListenerService ()
Public Methods
public Looper getLooper ()
This method is used to retrieve the looper all callbacks will run on. The default behavior is to construct a new background thread the first time called and use that thread. If a different looper is desired, subclasses should override this method.
public void onCapabilityChanged (CapabilityInfo capabilityInfo)
public void onChannelClosed (Channel channel, int closeReason, int appSpecificErrorCode)
Called when a channel is closed. This can happen through an explicit call to
Channel.close(GoogleApiClient)
or
Channel.close(GoogleApiClient, int)
on either side of the connection, or due
to disconnecting from the remote node.
Parameters
channel | |
---|---|
closeReason | the reason for the channel closing. One of
ChannelApi.ChannelListener.CLOSE_REASON_DISCONNECTED ,
ChannelApi.ChannelListener.CLOSE_REASON_REMOTE_CLOSE ,
ChannelApi.ChannelListener.CLOSE_REASON_LOCAL_CLOSE , or
ChannelApi.ChannelListener.CLOSE_REASON_CONNECTION_TIMEOUT |
appSpecificErrorCode | the error code specified on
Channel.close(GoogleApiClient) , or 0 if closeReason is
ChannelApi.ChannelListener.CLOSE_REASON_DISCONNECTED or
ChannelApi.ChannelListener.CLOSE_REASON_CONNECTION_TIMEOUT . |
public void onChannelClosed (ChannelClient.Channel channel, int closeReason, int appSpecificErrorCode)
Called when a channel is closed.
Parameters
channel | the ChannelClient.Channel
that was closed. |
---|---|
closeReason | the reason for the input closing. One of
ChannelClient.ChannelCallback.CLOSE_REASON_DISCONNECTED ,
ChannelClient.ChannelCallback.CLOSE_REASON_REMOTE_CLOSE ,
ChannelClient.ChannelCallback.CLOSE_REASON_LOCAL_CLOSE , or
ChannelClient.ChannelCallback.CLOSE_REASON_NORMAL . |
appSpecificErrorCode | the error code specified on
ChannelClient.close(ChannelClient.Channel, int) , or 0 if
closeReason is
ChannelClient.ChannelCallback.CLOSE_REASON_DISCONNECTED or
ChannelClient.ChannelCallback.CLOSE_REASON_NORMAL . |
public void onChannelOpened (Channel channel)
Called when a new channel is opened by a remote node.
public void onChannelOpened (ChannelClient.Channel channel)
Called when a new channel is opened by a remote node.
Parameters
channel | the ChannelClient.Channel
that was opened. |
---|
public void onCreate ()
public void onDataChanged (DataEventBuffer dataEvents)
Receives data changed events. The provided buffer will be closed after this method
completes. Use Freezable.freeze()
on items in the buffer to use them outside of this callscope.
If a data item is updated repeatedly in quick succession then these updates can be merged before onDataChanged is called. In this case a single data event will be delivered that conveys the final state of the relevant data item. When multiple data events are delivered in a single call then each event will correspond to the final state of a distinct data item.
Applications needing to track the state of all their data items may use
DataApi.getDataItems(GoogleApiClient)
on boot to retrieve all existing data
items.
public void onDestroy ()
public void onInputClosed (Channel channel, int closeReason, int appSpecificErrorCode)
Called when the input side of a channel is closed.
Parameters
channel | |
---|---|
closeReason | the reason for the input closing. One of
ChannelApi.ChannelListener.CLOSE_REASON_DISCONNECTED ,
ChannelApi.ChannelListener.CLOSE_REASON_REMOTE_CLOSE ,
ChannelApi.ChannelListener.CLOSE_REASON_LOCAL_CLOSE ,
ChannelApi.ChannelListener.CLOSE_REASON_NORMAL , or
ChannelApi.ChannelListener.CLOSE_REASON_CONNECTION_TIMEOUT |
appSpecificErrorCode | the error code specified on
Channel.close(GoogleApiClient) , or 0 if closeReason is
ChannelApi.ChannelListener.CLOSE_REASON_DISCONNECTED ,
ChannelApi.ChannelListener.CLOSE_REASON_NORMAL , or
ChannelApi.ChannelListener.CLOSE_REASON_CONNECTION_TIMEOUT . |
public void onInputClosed (ChannelClient.Channel channel, int closeReason, int appSpecificErrorCode)
Called when the input side of a channel is closed.
Parameters
channel | the ChannelClient.Channel
whose input was closed. |
---|---|
closeReason | the reason for the input closing. One of
ChannelClient.ChannelCallback.CLOSE_REASON_DISCONNECTED ,
ChannelClient.ChannelCallback.CLOSE_REASON_REMOTE_CLOSE ,
ChannelClient.ChannelCallback.CLOSE_REASON_LOCAL_CLOSE , or
ChannelClient.ChannelCallback.CLOSE_REASON_NORMAL . |
appSpecificErrorCode | the error code specified on
ChannelClient.close(ChannelClient.Channel, int) , or 0 if
closeReason is
ChannelClient.ChannelCallback.CLOSE_REASON_DISCONNECTED or
ChannelClient.ChannelCallback.CLOSE_REASON_NORMAL . |
public void onMessageReceived (MessageEvent messageEvent)
Receives message events.
public void onNodeMigrated (String nodeId, DataItemBuffer archive)
Receives notification for migration events when a device switches to a new network.
Parameters
nodeId | nodeId of the migrating node. |
---|---|
archive | archived DataItem from previous device, for watch it's empty. |
See Also
public void onOutputClosed (Channel channel, int closeReason, int appSpecificErrorCode)
Called when the output side of a channel is closed.
Parameters
channel | |
---|---|
closeReason | the reason for the output closing. One of
ChannelApi.ChannelListener.CLOSE_REASON_DISCONNECTED ,
ChannelApi.ChannelListener.CLOSE_REASON_REMOTE_CLOSE ,
ChannelApi.ChannelListener.CLOSE_REASON_LOCAL_CLOSE ,
ChannelApi.ChannelListener.CLOSE_REASON_NORMAL , or
ChannelApi.ChannelListener.CLOSE_REASON_CONNECTION_TIMEOUT |
appSpecificErrorCode | the error code specified on
Channel.close(GoogleApiClient) , or 0 if closeReason is
ChannelApi.ChannelListener.CLOSE_REASON_DISCONNECTED ,
ChannelApi.ChannelListener.CLOSE_REASON_NORMAL , or
ChannelApi.ChannelListener.CLOSE_REASON_CONNECTION_TIMEOUT . |
public void onOutputClosed (ChannelClient.Channel channel, int closeReason, int appSpecificErrorCode)
Called when the output side of a channel is closed.
Parameters
channel | the ChannelClient.Channel
whose output was closed. |
---|---|
closeReason | the reason for the output closing. One of
ChannelClient.ChannelCallback.CLOSE_REASON_DISCONNECTED ,
ChannelClient.ChannelCallback.CLOSE_REASON_REMOTE_CLOSE ,
ChannelClient.ChannelCallback.CLOSE_REASON_LOCAL_CLOSE , or
ChannelClient.ChannelCallback.CLOSE_REASON_NORMAL . |
appSpecificErrorCode | the error code specified on
ChannelClient.close(ChannelClient.Channel, int) , or 0 if
closeReason is
ChannelClient.ChannelCallback.CLOSE_REASON_DISCONNECTED or
ChannelClient.ChannelCallback.CLOSE_REASON_NORMAL . |
public void onPeerConnected (Node peer)
public void onPeerDisconnected (Node peer)
public Task<byte[]> onRequest (String nodeId, String path, byte[] request)
Called when an RPC request is received.
Parameters
nodeId | node ID of the sender |
---|---|
path | the path at which the RPC request was received |
request | the data associated with the RPC request |
Returns
- a future containing the response to be delivered back to the sender. null if the
request is not handled by this
MessageClient.RpcService
.