MessageApi | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Tools & Reference
  - Developer Stories

## Results

Loading...
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 conected 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.

Messages should generally contain ephemeral, smaller payloads. Use `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 |

Public Methods
abstract PendingResult<Status> | addListener(GoogleApiClient client, MessageApi.MessageListener listener) Registers a listener to receive `MessageEvent`s.
abstract PendingResult<Status> | removeListener(GoogleApiClient client, MessageApi.MessageListener listener) Removes a message listener.
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 receive `MessageEvent`s.

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

Removes a message listener.

#### 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.