【发布时间】:2020-10-08 09:13:03
【问题描述】:
我正在尝试使用华为健康套件从我的应用发送步数数据。步骤的插入似乎效果很好,但我在华为健康应用程序上看不到发送的值。正常吗?
我已经检查了current documentation 和sample code 上推荐的所有内容。
- 用户通过身份验证请求范围权限
Scopes.HEALTHKIT_STEP_BOTH - 根据this page在控制台上正确配置了Health kit
- 设备上的 Health 应用程序是最新的(版本 10.1.2.553)
- 最新的SDK版本集成为:
implementation "com.huawei.hms:health:5.0.3.300"和implementation "com.huawei.hms:hwid:5.0.3.301"
以下是我用来发送测试值的代码:
// create DataCollector
val dataCollector = DataCollector.Builder()
.setPackageName(context)
.setDataCollectorName("My awesome device")
.setDataType(DataType.DT_CONTINUOUS_STEPS_DELTA)
.setDataStreamName("STEPS_DELTA")
.setDataGenerateType(DataCollector.DATA_TYPE_RAW)
.build()
// create a sample set and add the sampleSet into the collector
val sampleSet = SampleSet.create(dataCollector)
val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
val start = dateFormat.parse("2020-10-07 09:00:00").time
val end = dateFormat.parse("2020-10-07 10:00:00").time
val samplePoint: SamplePoint = sampleSet.createSamplePoint()
.setTimeInterval(start, end, TimeUnit.MILLISECONDS).apply {
getFieldValue(Field.FIELD_STEPS_DELTA).setIntValue(5000)
}
sampleSet.addSample(samplePoint)
// retrieve DataController and insert the built data
val hiHealthOptions = HiHealthOptions.builder()
.addDataType(
DataType.DT_CONTINUOUS_STEPS_DELTA,
HiHealthOptions.ACCESS_WRITE
)
.addDataType(
DataType.DT_CONTINUOUS_STEPS_DELTA,
HiHealthOptions.ACCESS_READ
)
.build()
val signInHuaweiId = HuaweiIdAuthManager.getExtendedAuthResult(hiHealthOptions)
val dataController = HuaweiHiHealth.getDataController(context, signInHuaweiId)
val updateOptions = UpdateOptions.Builder()
.setTimeInterval(start, end, TimeUnit.MILLISECONDS)
.setSampleSet(sampleSet)
.build()
// update task
dataController.update(updateOptions).apply {
addOnSuccessListener {
Log.d(TAG, "onSuccess update")
}
addOnFailureListener { error ->
Log.e(TAG, "onFailure update, error: $error")
}
}
我清楚地看到该值已更新,因为它在 Logcat 中打印
onSuccess 更新
我还在DataController 上使用read 方法读取了值,并且能够检索到我的数据。
我问自己的问题是:
- 这些数据写入哪里:本地数据库和/或华为健康云?
- 我需要做一些事情来要求在 Health Application 上同步这些数据吗?
【问题讨论】:
标签: android kotlin huawei-mobile-services huawei-developers