com.google.android.gms.wearable.DataClient Java Examples

The following examples show how to use com.google.android.gms.wearable.DataClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PixelWatchFace.java    From PixelWatchFace with GNU General Public License v3.0 5 votes vote down vote up
private void syncToPhone() {
  String TAG = "syncToPhone";
  DataClient mDataClient = Wearable.getDataClient(getApplicationContext());
  PutDataMapRequest putDataMapReq = PutDataMapRequest.create("/watch-settings");

  putDataMapReq.setUrgent();
  Task<DataItem> putDataTask = mDataClient.putDataItem(putDataMapReq.asPutDataRequest());
  if (putDataTask.isSuccessful()) {
    Log.d(TAG, "Current stats synced to phone");
  }
}
 
Example #2
Source File: MainActivity.java    From PixelWatchFace with GNU General Public License v3.0 5 votes vote down vote up
private void syncToWear() {
  //Toast.makeText(this, "something changed, syncing to watch", Toast.LENGTH_SHORT).show();
  Snackbar.make(findViewById(android.R.id.content), "Syncing to watch...", Snackbar.LENGTH_SHORT)
      .show();
  loadPreferences();
  String TAG = "syncToWear";
  DataClient mDataClient = Wearable.getDataClient(this);
  PutDataMapRequest putDataMapReq = PutDataMapRequest.create("/settings");

      /* Reference DataMap retrieval code on the WearOS app
              mShowTemperature = dataMap.getBoolean("show_temperature");
              mUseCelsius = dataMap.getBoolean("use_celsius");
              mShowWeather = dataMap.getBoolean("show_weather");
              */

  putDataMapReq.getDataMap().putLong("timestamp", System.currentTimeMillis());
  putDataMapReq.getDataMap().putBoolean("show_temperature", showTemperature);
  putDataMapReq.getDataMap().putBoolean("use_celsius", useCelsius);
  putDataMapReq.getDataMap().putBoolean("show_weather", showWeather);
  putDataMapReq.getDataMap().putBoolean("show_temperature_decimal", showTemperatureDecimalPoint);
  putDataMapReq.getDataMap().putBoolean("use_thin", useThin);
  putDataMapReq.getDataMap().putBoolean("use_thin_ambient", useThinAmbient);
  putDataMapReq.getDataMap().putBoolean("use_gray_info_ambient", useGrayInfoAmbient);
  putDataMapReq.getDataMap().putBoolean("show_infobar_ambient", showInfoBarAmbient);
  putDataMapReq.getDataMap().putString("dark_sky_api_key", darkSkyAPIKey);
  putDataMapReq.getDataMap().putBoolean("use_dark_sky", useDarkSky);
  putDataMapReq.getDataMap().putBoolean("show_battery", showBattery);
  putDataMapReq.getDataMap().putBoolean("show_wear_icon", showWearIcon);
  putDataMapReq.getDataMap().putBoolean("advanced", advanced);

  putDataMapReq.setUrgent();
  Task<DataItem> putDataTask = mDataClient.putDataItem(putDataMapReq.asPutDataRequest());
  if (putDataTask.isSuccessful()) {
    Log.d(TAG, "Settings synced to wearable");
  }
}