private void sendWeatherData(Cursor weatherData, Context context) { // get high temperature string double high = weatherData.getDouble(COL_WEATHER_MAX_TEMP); String highString = Utility.formatTemperature(context, high); // get low temperature string double low = weatherData.getDouble(COL_WEATHER_MIN_TEMP); String lowString = Utility.formatTemperature(context, low); // get icon asset int weatherId = weatherData.getInt(COL_WEATHER_CONDITION_ID); int defaultImage = Utility.getIconResourceForWeatherCondition(weatherId); Bitmap weatherIcon = BitmapFactory.decodeResource(context.getResources(), defaultImage); Bitmap scaleBitmap = WearUtils.scaleBitmap(weatherIcon, 22, 22); Bitmap greyScaleIcon = WearUtils.toGrayscale(scaleBitmap); // https://developer.android.com/training/wearables/data-layer/assets.html sendWeatherDataItem(greyScaleIcon, highString, lowString); }
private void sendWeatherDataItem(Bitmap weatherIcon, String highString, String lowString) { Asset iconAsset = WearUtils.toAsset(weatherIcon); PutDataMapRequest dataMap = PutDataMapRequest.create(AppConstants.PATH_WEATHER_UPDATE); dataMap.getDataMap().putAsset(AppConstants.KEY_WEATHER_ICON, iconAsset); dataMap.getDataMap().putString(AppConstants.KEY_HIGH_TEMPERATURE, highString); dataMap.getDataMap().putString(AppConstants.KEY_LOW_TEMPERATURE, lowString); dataMap.getDataMap().putLong(AppConstants.KEY_TIMESTAMP, new Date().getTime()); PutDataRequest request = dataMap.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request) .setResultCallback( new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { Log.d( LOG_TAG, "Sending image was successful: " + dataItemResult.getStatus().isSuccess()); } }); }