3

Google Fit allows users to add activities manually and programatically. Is it possible to filter out manually or programtically added activities from either the Android Api or the REST Api?

I want to query for only activities that were actually tracked and recorded at the time they were performed.

Sam Leach
  • 12,746
  • 9
  • 45
  • 73
  • 1
    I am looking for the same. http://stackoverflow.com/questions/34496847/not-cheatable-google-fit-step-counter – Moritz Dec 29 '15 at 08:00
  • The only way I can think of doing it is reading the steps in real time so you know that the steps are real and have not been entered manually. Is there a way I can contact you? We could ask Google if they are considering adding what de need to their API. You can send me a DM on Twitter @sammleach – Sam Leach Dec 29 '15 at 16:40

2 Answers2

2

There is no proper way according to the documentation. But I found some solution to identify manual and automatic tracked activities in Android API.

DataSource ds = DataPoint.getOriginalDataSource()
String streamData = ds.getStreamIdentifier()

If "streamData" contains "user_input", then it assumes the activities to be manual activities, either it contains "detailed" for actual sensor recorded activities.

abdul khan
  • 843
  • 2
  • 7
  • 24
  • 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:07
  • Should be marked as answer. This worked perfectly – jmichas Aug 24 '21 at 03:37
0

I tried as suggested by Abdul Khan above but

DataSource ds = DataPoint.getOriginalDataSource();
String streamData = ds.getStreamIdentifier();

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

String packageName = ds.getAppPackageName();
String streamIdentifier = ds.getStreamIdentifier();

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.