public interface

MessageApi

com.google.android.gms.wearable.MessageApi

Class Overview

Exposes an API for components to send messages to other nodes.

Messages are delivered to connected network nodes. A message is considered successful if it has been queued for delivery to the specified node. A message will only be queued if the specified node is connected. The DataApi should be used for messages to nodes which are not currently connected (to be delivered on connection).

Messages should generally contain ephemeral, small payloads. Use assets with the DataApi to store more persistent or larger data efficiently.

A message is private to the application that created it and accessible only by that application on other nodes.

Summary

Nested Classes
interface MessageApi.MessageListener Used with addListener(GoogleApiClient, MessageApi.MessageListener) to receive message events. 
interface MessageApi.SendMessageResult Contains the request id assigned to the message. 
Constants
int UNKNOWN_REQUEST_ID A value returned by getRequestId() when sendMessage(GoogleApiClient, String, String, byte[]) fails.
Public Methods
abstract PendingResult<Status> addListener(GoogleApiClient client, MessageApi.MessageListener listener)
Registers a listener to be notified of received messages.
abstract PendingResult<Status> removeListener(GoogleApiClient client, MessageApi.MessageListener listener)
Removes a message listener which was previously added through addListener(GoogleApiClient, MessageListener).
abstract PendingResult<MessageApi.SendMessageResult> sendMessage(GoogleApiClient client, String nodeId, String path, byte[] data)
Sends byte[] data to the specified node.

Constants

public static final int UNKNOWN_REQUEST_ID

Constant Value: -1 (0xffffffff)

Public Methods

public abstract PendingResult<Status> addListener (GoogleApiClient client, MessageApi.MessageListener listener)

Registers a listener to be notified of received messages. Calls to this method should be balanced with removeListener(GoogleApiClient, MessageListener) to avoid leaking resources.

Callers wishing to be notified of events in the background should use WearableListenerService.

public abstract PendingResult<Status> removeListener (GoogleApiClient client, MessageApi.MessageListener listener)

Removes a message listener which was previously added through addListener(GoogleApiClient, MessageListener).

public abstract PendingResult<MessageApi.SendMessageResult> sendMessage (GoogleApiClient client, String nodeId, String path, byte[] data)

Sends byte[] data to the specified node.

Parameters
nodeId identifier for a particular node on the Android Wear network. Valid targets may be obtained through getConnectedNodes(GoogleApiClient) or from the host in getUri().
path identifier used to specify a particular endpoint at the receiving node
data small array of information to pass to the target node. Generally not larger than 100k
Returns
  • a PendingResult that is set when the message is queued to be sent. A successful result doesn't guarantee delivery.