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?
TL;DR: The code is OK, but you are trying to add a DataPoint
that is (in the API's eyes) bogus: you can't go over 100 meters/second
There are some internal validations in the API that check for limits on the input data, and throw an exceptions if the data doesn't comply.
Some decompiled code that shows these limits (in particular, you are interested in com.google.distance.delta
):
private zzbtw() {
HashMap var1;
(var1 = new HashMap()).put("latitude", new zzbty(-90.0D, 90.0D, (zzbtx)null));
var1.put("longitude", new zzbty(-180.0D, 180.0D, (zzbtx)null));
var1.put("accuracy", new zzbty(0.0D, 10000.0D, (zzbtx)null));
var1.put("bpm", new zzbty(0.0D, 1000.0D, (zzbtx)null));
var1.put("altitude", new zzbty(-100000.0D, 100000.0D, (zzbtx)null));
var1.put("percentage", new zzbty(0.0D, 100.0D, (zzbtx)null));
var1.put("confidence", new zzbty(0.0D, 100.0D, (zzbtx)null));
var1.put("duration", new zzbty(0.0D, 9.223372036854776E18D, (zzbtx)null));
var1.put("height", new zzbty(0.0D, 3.0D, (zzbtx)null));
var1.put("weight", new zzbty(0.0D, 1000.0D, (zzbtx)null));
var1.put("speed", new zzbty(0.0D, 11000.0D, (zzbtx)null));
this.zzhbn = Collections.unmodifiableMap(var1);
HashMap var2;
(var2 = new HashMap()).put("com.google.step_count.delta", zzc("steps", new zzbty(0.0D, 1.0E-8D, (zzbtx)null)));
var2.put("com.google.calories.consumed", zzc("calories", new zzbty(0.0D, 1.0E-6D, (zzbtx)null)));
var2.put("com.google.calories.expended", zzc("calories", new zzbty(0.0D, 5.555555555555555E-10D, (zzbtx)null)));
var2.put("com.google.distance.delta", zzc("distance", new zzbty(0.0D, 1.0E-7D, (zzbtx)null)));
this.zzhbm = Collections.unmodifiableMap(var2);
}
As the times are transformed from your time unit into nanoseconds (see DataPoint.setTimeInterval
), you end up with 1e-7 (as you are coming from milliseconds), and
Your data:
Long story short: try 8000 and see it working, try 8001 and see it failing
Unfortunately, I couldn't find any documentation about this, and had to debug step by step to get to this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With