问题
I tried to read user's height in Google Fit in android with this code :
DataReadRequest readHeightRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_HEIGHT)
.setTimeRange(FIRST_DAY_OF_MONTH_INMS, NOW_INMS, TimeUnit.MILLISECONDS)
.build();
But I only got a empty dataset with no dataPoint.
According to the DataType TYPE_HEIGHT documentation:
the start time should not be set.
So I tried to remove :
.setTimeRange(FIRST_DAY_OF_MONTH_INMS, NOW_INMS, TimeUnit.MILLISECONDS)
-> CRASH
java.lang.IllegalStateException: Invalid start time: 0
at com.google.android.gms.internal.jx.a(Unknown Source)
at com.google.android.gms.fitness.request.DataReadRequest$Builder.build(Unknown Source)
And I didn't see any documentation of method to set time range without endtime.
Is it possible to have a functional sample of code ?
[EDIT]
Solution : use a massive time range. I used the presentation of GoogleFit on June 25, 2014 for starting time :
DataReadRequest readRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_HEIGHT)
.setTimeRange(PresentationOfGoogleFit(June,25,2014), now, TimeUnit.MILLISECONDS)
.setLimit(1)
.build();
And it....works ! ;)
[/EDIT]
来源:https://stackoverflow.com/questions/28482176/read-the-height-in-googlefit-in-android