【问题标题】:Steps not visible on Huawei Health app after sending them from Heatlh Kit从 Health Kit 发送后,Huawei Health 应用程序上看不到步骤
【发布时间】:2020-10-08 09:13:03
【问题描述】:

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

我已经检查了current documentationsample 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


    【解决方案1】:

    这些数据写入哪里:本地数据库和/或华为 健康云?

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

    我需要做些什么来要求同步这些数据吗? 健康应用程序?

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


    更新:

    您可以查看最新版本的 Health Kit here。可以通过checkHealthAppAuthorizationgetHealthAppAuthorization接口检查用户是否已经授权华为健康应用向Health Kit开放数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多