从 Sony Band SWR12 检索心率数据
Retrieving Heart Rate Data from Sony Band SWR12
我正在努力从 Sony Band 2 (SWR12) 检索心率数据。我想使用 Google 适配传感器 API 来做到这一点。我在这里遵循 google 的示例和教程: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 Band 的任何人,请帮助我连接到手环。
我成功地通过以下代码记录并读取了分组数据:
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);
}
}
}
}
希望能帮到你。
一声问候
我正在努力从 Sony Band 2 (SWR12) 检索心率数据。我想使用 Google 适配传感器 API 来做到这一点。我在这里遵循 google 的示例和教程: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 Band 的任何人,请帮助我连接到手环。
我成功地通过以下代码记录并读取了分组数据:
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);
}
}
}
}
希望能帮到你。 一声问候