简体   繁体   中英

How to get all data of a particular DataType from google fitness store in android

I need to get all data of a particular DataType eg: "DataType.TYPE_HEART_RATE_BPM" from the fitness store. In the following code, I am requesting data with startTime and endTime and i am getting the response, but i want all the data of the particular DataType and not the data stored within the time interval. I have tried out the code given in How do I get the all time data from Google Fit API? but it didn't work

    Calendar calendar= Calendar.getInstance();
    calendar.setTime(new Date());
    long endTime=calendar.getTimeInMillis();
    calendar.add(Calendar.WEEK_OF_YEAR, -1);
    long startTime = calendar.getTimeInMillis();

    DataReadRequest readRequest = new DataReadRequest.Builder()
    .read(DataType.TYPE_HEART_RATE_BPM)
    .bucketByTime(5, TimeUnit.MINUTES)
    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
    .enableServerQueries()
    .build();

This worked for me. Do not use .bucketByTime() attribute. The response will be a List of DataSet. Starting date is Google Fit's initial release date ( https://en.wikipedia.org/wiki/Google_Fit )

Calendar cal = Calendar.getInstance();

Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.set(2014, 9, 28);
cal.set(Calendar.HOUR_OF_DAY, 0); 
cal.set(Calendar.MINUTE, 0);
long startTime = cal.getTimeInMillis();

DataReadRequest readRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_STEP_COUNT_DELTA)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.enableServerQueries()
.build();

To read the response:

if (response.getDataSets().size()>0){
       for (DataSet dataSet :response.getDataSets())
              dumpDataSet(dataSet);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM