从 Health Kit 发送的步骤在华为健康应用程序上不可见

Steps not visible on Huawei Health app after sending them from Heatlh Kit

我正在尝试使用 Huawei Health kit 从我的应用程序发送步数数据。插入步骤似乎效果很好,但我在华为健康应用程序上看不到发送的值。正常吗?

我已经检查了 current documentation and in the sample code 上推荐的所有内容。

下面是我用来发送测试值的代码:

    // 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 update

我还在 DataController 上使用 read 方法读取了值,并且能够检索到我的数据。

我问自己的问题是:

Where are this data written: in a local database and/or in a Huawei Health Cloud ?

在本地数据库和华为健康云中。

Do I need to do something to ask the synchronisation of this data on the Health Application ?

目前Health Kit不支持将数据直接写入健康应用和服务。 2020年10月下旬支持读取健身和健康数据,2021年1月支持将数据直接写入健康APP和服务。


更新:

可以查看Health Kit最新版本here. The checkHealthAppAuthorization and getHealthAppAuthorization可以通过API查看用户是否授权华为运动健康应用向Health Kit开放数据