add Google Fit distance (DataPoint out of range)

Viewed 1339

My code

val startTime = 1510241100000 // 2017-11-09T15:25:00+00:00
val endTime = 1510241180000   // 2017-11-09T15:26:20+00:00
val distance = 12000.0f

val distanceDataSource = DataSource.Builder()
    .setAppPackageName(packageName)
    .setDataType(DataType.AGGREGATE_DISTANCE_DELTA)
    .setType(DataSource.TYPE_RAW)
    .build()
val distanceDataSet = DataSet.create(distanceDataSource)
val distancePoint = distanceDataSet.createDataPoint()
    .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
distancePoint.getValue(Field.FIELD_DISTANCE).setFloat(distance)
    distanceDataSet.add(distancePoint) // here is the crash

crashed with java.lang.IllegalArgumentException: DataPoint out of range, if the diff between startTime and endTime is less then 10 minutes.

Has someone an idea, what is wrong with my code?

1 Answers
Related