title: Sending messages from Android Wear to host device
body: <p>I'm writing a custom Android Wear application that's supposed to fire a one-off message to the connected host device (the phone). Digging through the API, I found the following tutorial that should work well: <a href="http://developer.android.com/training/wearables/data-layer/messages.html">http://developer.android.com/training/wearables/data-layer/messages.html</a></p>
  
  <p>My Android app has a WearableListenerService and my Android Wear app fires off messages using the Message API. The WearableListenerService get's called when the emulator gets connected based on logging the following method, so I'm pretty sure the service is wired up fine</p>
  
  <pre><code>@Override
  public void onPeerConnected(Node peer) {
      super.onPeerConnected(peer);
  
      String id = peer.getId();
      String name = peer.getDisplayName();
  
      Log.d(LOG_TAG, "Connected peer name &amp; ID: " + name + "|" + id);
  }
  </code></pre>
  
  <p>Log output:</p>
  
  <pre><code>/AndroidWearListenerService(19892): Connected peer name &amp; ID: facdc219-37f5-4326-8fa6-1c8b8d3b6669|facdc219-37f5-4326-8fa6-1c8b8d3b6669
  </code></pre>
  
  <p>However, the onMessageReceived method never gets triggered:</p>
  
  <pre><code>@Override
  public void onMessageReceived(MessageEvent messageEvent) {
      Log.d(LOG_TAG, "MessageEvent received: " + messageEvent.getData());
      //do work
  }
  </code></pre>
  
  <p>Here's my Android Wear code. I've removed most of the boiler plate code leaving only the necessary bits</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_my);
  
      final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
              .addApi(Wearable.API)
              .build();
  
      googleApiClient.connect();
  
      final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
      stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
          @Override
          public void onLayoutInflated(WatchViewStub stub) {
              fireMessage();
          }
  
          private void fireMessage() {
              // Send the RPC
              PendingResult&lt;NodeApi.GetConnectedNodesResult&gt; nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient);
              nodes.setResultCallback(new ResultCallback&lt;NodeApi.GetConnectedNodesResult&gt;() {
                  @Override
                  public void onResult(NodeApi.GetConnectedNodesResult result) {
                      for (int i = 0; i &lt; result.getNodes().size(); i++) {
                          Node node = result.getNodes().get(i);
                          String nName = node.getDisplayName();
                          String nId = node.getId();
                          Log.d(TAG, "Node name and ID: " + nName + " | " + nId);
  
                          Wearable.MessageApi.addListener(googleApiClient, new MessageApi.MessageListener() {
                              @Override
                              public void onMessageReceived(MessageEvent messageEvent) {
                                  Log.d(TAG, "Message received: " + messageEvent);
                              }
                          });
  
                          PendingResult&lt;MessageApi.SendMessageResult&gt; messageResult = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(),
                                  PATH, null);
                          messageResult.setResultCallback(new ResultCallback&lt;MessageApi.SendMessageResult&gt;() {
                              @Override
                              public void onResult(MessageApi.SendMessageResult sendMessageResult) {
                                  Status status = sendMessageResult.getStatus();
                                  Log.d(TAG, "Status: " + status.toString());
                                  if (status.getStatusCode() != WearableStatusCodes.SUCCESS) {
                                      alertButton.setProgress(-1);
                                      label.setText("Tap to retry. Alert not sent :(");
                                  }
                              }
                          });
                      }
                  }
              });
          }
      });
  }
  </code></pre>
  
  <p>Logging seems to indicate the message was sent successfully, but the Android app's WearableListenerService.onMessageReceived never fires.</p>
  
  <pre><code>D/MyWearApp MyActivity( 2014): Node name and ID: a2ba665d-a559-4a95-91d2-c16fc7873e28 | a2ba665d-a559-4a95-91d2-c16fc7873e28
  D/MyWearApp MyActivity( 2014): Status: Status{statusCode=SUCCESS, resolution=null}
  </code></pre>
  
  <p>Any ideas?</p>