12

From the smartphone by using HistoryAPI If I ask for user's history and DataType.TYPE_HEART_RATE_BPM for the last past hour, starting from the current time, I miss data from the last half hour.

If I ask them to Google Fit with the same procedure from the smartwatch it's all fine.

So it's not a matter of data fetching because it depends on device.

Maybe it's a problem of synchronization? How do I programmatically force an update of records in the repository of Google Fitness Store?

This is what I'm talking about.

EDIT: this is how I build a request

      DataReadRequest readRequest = new DataReadRequest.Builder()
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .enableServerQueries()
            .read(dataType)
            .build();
user3290180
  • 4,260
  • 9
  • 42
  • 77
  • As @Rakki s said in the answer to [his SO question](http://stackoverflow.com/questions/26670836/google-fit-data-is-diffrent-from-device-to-device-with-same-account), > We can read global data (Cloud) by adding the `.enableServerQueries()` > in `DataReadRequest`. He refers to [`enableServerQueries()`](https://developers.google.com/android/reference/com/google/android/gms/fitness/request/SessionReadRequest.Builder#enableServerQueries%28%29) of the `SessionReadRequest.Builder`. Have you tried that? – serv-inc Jul 02 '15 at 13:04
  • Yes, I did, but still missing parts of data. – user3290180 Jul 05 '15 at 08:00
  • The same problem happens when the watch is out of phone's range. When they are paired again I can't get the data collected in the meantime. – user3290180 Jul 05 '15 at 08:11

1 Answers1

5

Have you given the devices enough time to synchronize all data before making a request? When you request data from the HistoryAPI on the phone it will be fetched from the cloud. However, when you request data from the watch it will only be local data from that wearable device. If the devices have been out of range I assume that it would take some time, after re-connecting, before the watch data is available in the cloud. As far as I know there's no way of forcing such an update to happen faster/on demand.

A possible workaround would be to check the time stamp of the data points and use local data on the watch if there's data missing from the request made on the phone.

TofferJ
  • 4,678
  • 1
  • 37
  • 49
  • Yes, when they were connected the update was made in about a minute or two. When they were disconnected and reconnected the update was a russian roulette and sometimes it missed data. – user3290180 Jul 08 '15 at 12:03
  • a method to force at least a local update between devices would be useful – user3290180 Jul 08 '15 at 12:04
  • Yeah the data is synched from the watch every minute when they are paired. Not sure how long it takes after a re-connect, but it shouldn't really be much more than that. Personally I ended up using the Fit API on the watch only to avoid these kind of issues. Hopefully Google will improve the API in the upcoming releases. In the meantime I guess you have to aggregate the data yourself, using the time stamps. – TofferJ Jul 08 '15 at 12:19
  • what if I send data via WearableApi and then save it with HistoryApi? These may be duplicates when sync will be done? (if it'll happen...) Otherwise I have to take the risk to miss data from the phone if the watch is isolated for a while – user3290180 Jul 08 '15 at 14:54
  • I don't think you will get duplicates, because there's a few things that happens when you save data to the API. If you have data sets from different sources (I'm just not sure if this will be considered as different sources) that were collected during the same period of time, only the data from the source that's considered to be the more accurate one will be saved (or maybe even some sort of average value will be used). This is to avoid duplicates if you e.g. are out running with both your phone and watch. – TofferJ Jul 09 '15 at 09:39
  • IF you go with the solution that potentially miss data you can always add a message to the user explaining this when it's disconnected, just to avoid confusion and frustration. – TofferJ Jul 09 '15 at 09:40