简体   繁体   English

如何使用Google Fit Android SDK从所有数据源读取数据?

[英]How can I read data from all data sources using google fit android sdk?

I need help understanding the documentation. 我需要了解文档的帮助。 I am developing an android application. 我正在开发一个android应用程序。 Aim of my application is to show user total number of steps he/she has taken over last n days. 我的应用程序的目的是显示用户在过去n天内执行的步骤总数。 These steps would include any step_count that user has synced to google fit store using a wearable or from multiple mobile pedometers. 这些步骤将包括用户已使用可穿戴设备或多个移动计步器同步到Google Fit Store的任何step_count。

I am trying to use android sdk with history api for retrieving data from google fit store. 我正在尝试使用带有历史记录api的android sdk从Google Fit商店中检索数据。 However it seems like I am not fetching all the data. 但是,似乎我没有获取所有数据。 I am only able to get step_count for users current mobile pedometer. 我只能为用户当前的移动计步器获取step_count。

To further clarify here is example use case: For example App A : Syncs 10 steps to google fit store for time T1 to T2 App B : Syncs another 10 steps to google fit store T2 to T3 Using App C : In my app I want to show total steps for time T1 to T3 ? 为了进一步澄清,这里是示例用例:例如, 应用A :将10步同步到Google Fit Store,时间为T1到T2; 应用B :将另外10步同步到Google Fit Store T2到T3;使用应用C :在我的应用中,我想显示时间T1至T3的总步数?

does fit android sdk allows to fetch all the steps user has performed ? 是否适合android sdk允许提取用户执行的所有步骤? Or does it only provide the steps that are relevant to users current device ? 还是仅提供与用户当前设备​​相关的步骤?

For further reference here is the code I am using to fetch user's data. 为了进一步参考,这里是我用来获取用户数据的代码。

fun getReadDataRequestBuilderAggregated(startDate: Date, endDate: Date): DataReadRequest? {
        val cal = Calendar.getInstance()
        cal.time = startDate.setDayStartTime()
        var startTime = cal.timeInMillis
        cal.time = endDate
        var endTime = cal.timeInMillis
        return if (startTime>endTime) {
            null
        } else {

            return DataReadRequest.Builder()
                    .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
                    .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
                    .bucketByTime(TIME_PERIOD_GROUP_DATA_DAYS, TimeUnit.DAYS)
                    .enableServerQueries()
                    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS).build()
        }
    }  

In my case I did not added subscription to specific data type as described in the documentation . 就我而言,我没有按照文档中所述为特定数据类型添加订阅。 It is necessary to add subscription if you want to read data from fitness store. 如果要从健身商店中读取数据,则必须添加订阅。 As creating this subscription will sync data recorded from your source as well retrieve data from other sources. 创建此订阅时,将同步从您的源记录的数据,以及从其他源检索的数据。

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

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