Search code examples
androidwear-osgoogle-fit

Fitness.HistoryApi.readDailyTotal hangs indefinitely


I am writing an Android Wear application. I am trying to query the step delta and whenever I do, readDailyTotal hangs indefinitely. I've tried this on an emulator and on a physical device with no luck.

Here is the code that I use to connect the client (I am loading local data to the device):

    mClient = new GoogleApiClient.Builder(this)
      .useDefaultAccount()
      .addApi(Fitness.HISTORY_API)
      .addApi(Fitness.RECORDING_API)
      .addOnConnectionFailedListener(this)
      .addConnectionCallbacks(this)
      .build();
    mClient.connect();

I subscribe to the recording API with:

    Fitness.RecordingApi.subscribe(mClient, DataType.TYPE_STEP_COUNT_DELTA)
      .setResultCallback( /* some stuff */);

Finally, I query the data in an AsyncTask (and where it hangs) with:

    PendingResult<DailyTotalResult> result = Fitness.HistoryApi.readDailyTotal(mClient, DataType.TYPE_STEP_COUNT_DELTA);

I've run through the debugger and have isolated the hanging to that line.

Any ideas would be appreciated because I've been scratching my head and searching for a few days now.


Solution

  • readDailyTotal does not need to be called within AsyncTask as it is already an async operation (that's why it returns a PendingResult).