예제 #1
0
 protected Void doInBackground(Void... params) {
   DataReadRequest readRequest = queryFitnessData(); // Obtenemos los resultados de las query
   DataReadResult dataReadResult =
       Fitness.HistoryApi.readData(mClient, readRequest).await(1, TimeUnit.MINUTES);
   Log.i(TAG, "Intentando imprimir datos");
   uploadData(dataReadResult);
   return null;
 }
    private void getTotalDistance() {

      Log.d(TAG, "getTotalDistance()");

      if ((mGoogleApiClient != null) && (mGoogleApiClient.isConnected()) && (!mDistanceRequested)) {

        mDistanceRequested = true;

        PendingResult<DailyTotalResult> distanceResult =
            Fitness.HistoryApi.readDailyTotal(mGoogleApiClient, DataType.TYPE_DISTANCE_DELTA);

        distanceResult.setResultCallback(this);
      }
    }
예제 #3
0
  @Override
  public void execute(Context ctx, Map<String, Value> context)
      throws UnknownObjectException, RuleExecutionException {
    GoogleApiClient client = ((GoogleFitChannel) channel).acquireClient(ctx);

    try {
      long now = System.currentTimeMillis();
      DataReadRequest.Builder builder =
          new DataReadRequest.Builder()
              .read(dataType.getType())
              .setTimeRange(now - 24 * 3600 * 1000, now, TimeUnit.MILLISECONDS);

      DataReadResult result = Fitness.HistoryApi.readData(client, builder.build()).await();

      DataSet dataSet = result.getDataSet(dataType.getType());
      List<DataPoint> dataPoints = dataSet.getDataPoints();

      DataPoint latest = null;
      for (DataPoint point : dataPoints) {
        if (latest == null || point.getTimestampNanos() >= latest.getTimestampNanos())
          latest = point;
      }
      if (latest == null) throw new RuleExecutionException("Google API did not return any data");

      com.google.android.gms.fitness.data.Value value = latest.getValue(dataType.getField());

      String dataTypeId = dataType.toString();

      if (value.getFormat() == Field.FORMAT_INT32)
        context.put(FITNESS_CURRENT_VALUE_PREFIX + dataTypeId, new Value.Number(value.asInt()));
      else if (value.getFormat() == Field.FORMAT_FLOAT)
        context.put(FITNESS_CURRENT_VALUE_PREFIX + dataTypeId, new Value.Number(value.asFloat()));
      else throw new RuleExecutionException("Google Fit data point has invalid type");
    } finally {
      ((GoogleFitChannel) channel).releaseClient();
    }
  }