6

We are working on an Android application which queries Google Fit API to retrieve Steps, Calories and Distance parameter. We want to query activities which are NOT manually entered by user (or somehow identify these kind of activity and ignore them).

User's can manually load Walking, Running etc activity, and we want to ignore such activities. We looked into History APIs and Activity Fields, but it seems there is no way to identify whether activities are manually logged or automatically added by other apps OR phone sensors OR wearable devices.

Can someone knows a way to get activities which are not manually logged by user?

UPDATE

Check below thread on Google Fit Developer Community, it may help someone

https://plus.google.com/u/0/105650643673857572241/posts/fET6zKYFq4K

Amit
  • 1,365
  • 8
  • 15

2 Answers2

7

This may not be the correct way to identify sensor detected steps, but with some testing, it almost matches steps which I think recorded by sensor.

DataSource ds = DataPoint.getOriginalDataSource()

String dataStream = ds.getStreamIdentifier()

If "dataStream" string contains soft_step_delta, then we can assume that steps are recorded from phone sensor. I haven't tested it with wearable device.

Amit
  • 1,365
  • 8
  • 15
  • Have tried DataPoint.getOriginalDataSource().getAppPackageName() and it returns 'null'. Have also tried DataPoint.getOriginalDataSource().getStreamIdentifier() and it has some value which is not readable. – Vrajesh Hirani Jul 22 '19 at 12:06
2

I tried as suggested by Amit above but

DataPoint.getOriginalDataSource().getStreamIdentifier();

/*I also tried but could not achieve what I wanted*/

DataPoint.getOriginalDataSource().getStreamName();
DataPoint.getOriginalDataSource().getAppPackageName();

did not work at least for me while retrieving data. I ended up using readDailyTotalFromLocalDevice() as shown below in order to capture steps captured by device only.

Fitness.HistoryApi.readDailyTotalFromLocalDevice(mApiClient, DataType.TYPE_STEP_COUNT_DELTA).await(1, TimeUnit.MINUTES)

I cross checked the same with some of the apps that avoids manual entries in their app and the count provided by the function above is exactly the same.

Note: If a user is having multiple devices and is using the app on all of them, readDailyTotalFromLocalDevice() will have different value for each and every device since the function is responsible for returning device specific data only.

  • Vrajesh - My issue was 3+ years old and it might possible that Google Fit APIs has been changed. I wasn't working on Google Fit API since last 2 years and so not up to date with the changes. – Amit Sep 30 '19 at 09:57
  • @Amit not an issue. I just mentioned the same in the answer so that anyone who has recently started working on the Google Fit APIs can be aware of this. – Vrajesh Hirani Oct 04 '19 at 06:20