title: Android wearables: How to handle the event of a connected device?
body: <p>From the smartwatch I'd like to intercept the event of the connection to a smartphone. This is automatically managed by Android and Android Wear so I need to get this event from my app running on the watch.</p>
  
  <p>I found out this on WearableAPI to be notified without polling Wearable.NodeApi.getConnectedNodes</p>
  
  <pre><code>public class MyService extends WearableListenerService {
    @Override
    public void onPeerConnected(Node peer) {
      Log.i("my wear service", "connected");
      super.onPeerConnected(peer);
      // here I would use MessageAPI to send data saved on "disk" to the smartphone
    }
  }
  </code></pre>
  
  <p>Is it the right way? So is this a normal Service? Do I have to start it or is it automatically running in background?
  Are there any other ways to perform this task?</p>
  
  <p>this is the <a href="https://developers.google.com/android/reference/com/google/android/gms/wearable/WearableListenerService" rel="nofollow">reference</a></p>