简体   繁体   English

如何从android中的谷歌健身商店获取特定数据类型的所有数据

[英]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.我需要从健身商店获取特定数据类型的所有数据,例如:“DataType.TYPE_HEART_RATE_BPM”。 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.在下面的代码中,我使用 startTime 和 endTime 请求数据并且我得到了响应,但我想要特定 DataType 的所有数据,而不是存储在时间间隔内的数据。 I have tried out the code given in How do I get the all time data from Google Fit API?我已经尝试了如何从 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.不要使用 .bucketByTime() 属性。 The response will be a List of DataSet.响应将是一个数据集列表。 Starting date is Google Fit's initial release date ( https://en.wikipedia.org/wiki/Google_Fit )开始日期是 Google Fit 的初始发布日期 ( 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在android中使用SQlite存储和检索特定用户的数据 - How to store and retrieve data for a particular user using SQlite in android 如何从android中的特定JSONObects获取ArrayLists? - how to get ArrayLists from particular JSONObects in android? 是否可以使用 Google Fit REST API 在同一网络应用程序中聚合来自多个用户的健身数据? - Is it possible to aggregate fitness data from multiple users in the same web app using the Google Fit REST API? 如何从 Firebase 获取每个月的所有数据,以便在 Android 中进行计算 - How to get all data at each month from Firebase for calculation in Android 如何从XML中的特定标记获取所有值? - How I can get all values from particular tag in XML? 如何从cli中获取特定JDK附带的所有类的列表? - How to get list of all classes coming with particular JDK from cli? 如何在Android应用中存储Google地图标记数据? - How to store google map marker data in android app? 如何从android中的xml标签获取特定值 - How to get particular values from xml tags in android 如何从JAVA Android中的String获取某些特定单词? - how to get some particular word from String in JAVA Android? 如何从谷歌获取所有链接 - How to get all links from google
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM