title: Recieving data from Android watch to phone
body: <p>I am trying text transfer from watch to phone and phone to watch. I am able to send the data from both the devices to each other, and my watch is able to receive the data too. <br>
  There seems to be some problem in my Receive_Data_Phone class. It doesn't detect any data which i am sending through watch.<br>
  I have shared the code and Logcat Output.<br>
  <br>
  Recieve_Data.java
  <br></p>
  
  <pre><code>public class Recieve_Data extends WearableListenerService {
  private static final String TAG = "@@##";
  private GoogleApiClient mGoogleApiClient;
  
  @Override
  public void onCreate() {
      super.onCreate();
      mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(
              Wearable.API).build();
      mGoogleApiClient.connect();
      System.out.println("Inside RecieveData onCreate()");
  
  
  }
  
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
      final List&lt;DataEvent&gt; events = FreezableUtils
              .freezeIterable(dataEvents);
      dataEvents.close();
      System.out.println("Inside OnDataChanged()");
  
      if (!mGoogleApiClient.isConnected()) {
          ConnectionResult connectionResult = mGoogleApiClient
                  .blockingConnect(30, TimeUnit.SECONDS);
          if (!connectionResult.isSuccess()) {
              Log.e(TAG,"WEAR :: Service failed to connect to GoogleApiClient.");
              return;
          }
      } else {
          Log.e(TAG,"WEAR :: Service connected to GoogleApiClient.");
      }
  
      for (DataEvent event : events) {
          if (event.getType() == DataEvent.TYPE_CHANGED) {
              String path = event.getDataItem().getUri().getPath();
              Log.d(TAG, "DataEvent.TYPE_CHANGED, path = " + path);
  
                  /*          if (Constants.PATH_SERVER_RESPONSE.equals(path)) {
                  // Get the data out of the event
                  DataMapItem dataMapItem = DataMapItem.fromDataItem(event
                          .getDataItem());
                  final String responseString = dataMapItem.getDataMap()
                          .getString(Constants.KEY_TITLE);
                  Log.d(TAG, "DataEvent notif responseString: "
                          + responseString);
  
                  Intent intent = new Intent("my-event");
                  intent.putExtra("message", responseString);
                  LocalBroadcastManager.getInstance(this).sendBroadcast(
                          intent);
              } 
  
               */         
  
               if (Constant_Vars.PATH_OBJECTIVE.equals(path)) {
                  DataMapItem dataMapItem = DataMapItem.fromDataItem(event
                          .getDataItem());
                  String msg = dataMapItem.getDataMap().getString(
                          Constant_Vars.KEY_OBJECTIVE);
                  int message = Integer.parseInt(msg);
                  Log.d(TAG, "WEAR:: String " + message);
  
  
              } else {
                  Log.d(TAG, "Unrecognized path: " + path);
              }
          }
      }
  }
  
  @Override
  public void onMessageReceived(MessageEvent messageEvent) {
      Log.d(TAG, "MOBILE:: onMessageReceived messageEvent path: "
              + messageEvent.getPath());
  
      if (messageEvent.getPath().equals(Constant_Vars.PATH_OBJECTIVE)) {
          Toast.makeText(getBaseContext(), "Service Working",
                  Toast.LENGTH_SHORT).show();
  
      } else {
          Toast.makeText(getBaseContext(), "Unknown request",
                  Toast.LENGTH_SHORT).show();
      }
  }
  }
  </code></pre>
  
  <p>Receive_Data_Phone.java<br></p>
  
  <pre><code>public class Recieve_Data_Phone extends WearableListenerService {
  
  
  private static final String TAG = "@@##";
  
  private GoogleApiClient mGoogleApiClient;
  
  @Override
  public void onCreate() {
      super.onCreate();
      mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(
              Wearable.API).build();
      mGoogleApiClient.connect();
      System.out.println("Inside RecieveData onCreate()");
  
  
  }
  
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
      final List&lt;DataEvent&gt; events = FreezableUtils
              .freezeIterable(dataEvents);
      dataEvents.close();
      System.out.println("Inside OnDataChanged()");
  
      if (!mGoogleApiClient.isConnected()) {
          ConnectionResult connectionResult = mGoogleApiClient
                  .blockingConnect(30, TimeUnit.SECONDS);
          if (!connectionResult.isSuccess()) {
              Log.e(TAG,"PHONE :: Service failed to connect to GoogleApiClient.");
              return;
          }
      } else {
          Log.e(TAG,"PHONE :: Service connected to GoogleApiClient.");
      }
  
      for (DataEvent event : events) {
          if (event.getType() == DataEvent.TYPE_CHANGED) {
              String path = event.getDataItem().getUri().getPath();
              Log.d(TAG, "DataEvent.TYPE_CHANGED, path = " + path);
  
                  /*          if (Constants.PATH_SERVER_RESPONSE.equals(path)) {
                  // Get the data out of the event
                  DataMapItem dataMapItem = DataMapItem.fromDataItem(event
                          .getDataItem());
                  final String responseString = dataMapItem.getDataMap()
                          .getString(Constants.KEY_TITLE);
                  Log.d(TAG, "DataEvent notif responseString: "
                          + responseString);
  
                  Intent intent = new Intent("my-event");
                  intent.putExtra("message", responseString);
                  LocalBroadcastManager.getInstance(this).sendBroadcast(
                          intent);
              } 
  
               */         
  
               if (Constant_Vars.PATH_FLAG.equals(path)) {
                  DataMapItem dataMapItem = DataMapItem.fromDataItem(event
                          .getDataItem());
                  String msg = dataMapItem.getDataMap().getString(
                          Constant_Vars.KEY_FLAG);
                  //int message = Integer.parseInt(msg);
                  Log.d(TAG, "PHONE:: String " + msg);
  
  
              } else {
                  Log.d(TAG, "Unrecognized path: " + path);
              }
          }
      }
  }
  
  @Override
  public void onMessageReceived(MessageEvent messageEvent) {
      Log.d(TAG, "MOBILE:: onMessageReceived messageEvent path: "
              + messageEvent.getPath());
  
      if (messageEvent.getPath().equals(Constant_Vars.PATH_FLAG)) {
          Toast.makeText(getBaseContext(), "Service Working",
                  Toast.LENGTH_SHORT).show();
  
      } else {
          Toast.makeText(getBaseContext(), "Unknown request",
                  Toast.LENGTH_SHORT).show();
      }
  }
  }
  </code></pre>