从Sony Band SWR12中检索心率数据

时间:2017-02-09 17:12:07

标签: sony sony-smartwatch sony-lifelog-api

我正在从Sony Band 2(SWR12)中检索心率数据。我想使用Google Fit Sensors API执行此操作。我在这里按照谷歌的示例和教程:https://github.com/googlesamples/android-fit/blob/master/BasicSensorsApi/app/src/main/AndroidManifest.xml

启用Fit API并创建我的身份验证令牌后,我现在可以读取设备位置。

但是,当我将数据源更改为:     .setDataTypes(DataType.AGGREGATE_HEART_RATE_SUMMARY) 应用程序崩溃。

之前曾使用过Fit API和Sony乐队的人,请帮我连接乐队。

1 个答案:

答案 0 :(得分:0)

我设法使用以下代码记录和读取分组数据:

private void suscribeDataFitness(){
    Fitness.RecordingApi.subscribe(mApiClient, DataType.AGGREGATE_HEART_RATE_SUMMARY)
            .setResultCallback(mSubscribeResultCallback);

}


private void readDataFitnessHistory()
{
    // Setting a start and end date using a range of 1 week before this moment.
    Calendar cal = Calendar.getInstance();
    Date now = new Date();
    cal.setTime(now);
    long endTime = cal.getTimeInMillis();

    cal.add(Calendar.DAY_OF_YEAR, -1);
    long startTime = cal.getTimeInMillis();

    java.text.DateFormat dateFormat = getDateInstance();
    Log.d(TAG, "Range Start: " + dateFormat.format(startTime) + " Millis : " + startTime);
    Log.d(TAG, "Range End: " + dateFormat.format(endTime)  + " Millis : " + endTime);

   final DataReadRequest readRequest = new DataReadRequest.Builder()
            //.read(DataType.TYPE_STEP_COUNT_DELTA)
            //.read(DataType.TYPE_HEART_RATE_BPM)
            //.read(ESTIMATED_STEP_DELTAS)
            .aggregate(DataType.AGGREGATE_HEART_RATE_SUMMARY)
            .enableServerQueries()
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .bucketByTime(1, TimeUnit.HOURS)
            .build();


    // Invoke the History API to fetch the data with the query and await the result of
    // the read request.
    DataReadResult dataReadResult =
            Fitness.HistoryApi.readData(mApiClient, readRequest).await(1, TimeUnit.MINUTES);
    showDataBuckets(dataReadResult);

}

final DataReadRequest readRequest = new DataReadRequest.Builder()
            //.read(DataType.TYPE_STEP_COUNT_DELTA)
            //.read(DataType.TYPE_HEART_RATE_BPM)
            //.read(ESTIMATED_STEP_DELTAS)
            .aggregate(DataType.AGGREGATE_HEART_RATE_SUMMARY)
            .enableServerQueries()
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .bucketByTime(1, TimeUnit.HOURS)
            .build();


private void showDataBuckets(DataReadResult dataReadResult) {
    //Used for aggregated data
    if (dataReadResult.getBuckets().size() > 0) {
        Log.d(TAG,"History: "+ "Number of buckets: " + dataReadResult.getBuckets().size());
        for (Bucket bucket : dataReadResult.getBuckets()) {
            List<DataSet> dataSets = bucket.getDataSets();
            for (DataSet dataSet : dataSets) {
                showDataSet(dataSet);
            }
        }
    }
}

我希望我能帮助你。 问候语