Read the height in GoogleFit in Android

萝らか妹 提交于 2019-12-06 05:22:13

问题


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

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