Google Fit Api filter manually added activities

冷暖自知 提交于 2019-12-01 12:11:31

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!