Steps Data receive from History api is not matched with google fit

天涯浪子 提交于 2019-12-08 08:53:26

see the FAQ, which explain the behavior quite literally, which you're descibing.

this is possibly the closest one can get; assuming the latest Play Services installed on device:

DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
   .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
   .setType(DataSource.TYPE_DERIVED)
   .setStreamName("estimated_steps")
   .setAppPackageName("com.google.android.gms")
   .build();

DataReadRequest readRequest = new DataReadRequest.Builder()
   .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
   .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
   .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
   .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
   .bucketByTime(1, TimeUnit.DAYS)
   .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
   .build();

it's quite the same, except TYPE_CALORIES_EXPENDED. alternatively, you could record you own sessions - which are not just estimated_steps, but have a unique session identifier.

I am using history api in my app and compared the output with Google FIT app, they are quite same.

val c = GregorianCalendar()
    c.set(Calendar.HOUR_OF_DAY, 0) //anything 0 - 23
    c.set(Calendar.MINUTE, 0)
    c.set(Calendar.SECOND, 0)
    var endTime = /*date.time + dayInMS*/(getCurrentUTCDate()*1000)
    var startTime = (ConfigVariable.appLastUpdateTime*1000) //converting last updated data from second to MS
    val readRequest = DataReadRequest.Builder()
            .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
            .bucketByTime(1  , TimeUnit.DAYS)
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .build()
    val pendingResult = Fitness.HistoryApi.readData(mGoogleApiClient,readRequest)
    pendingResult.setResultCallback(this)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!