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

662 views Asked by At

I am trying to send steps data from my app using the Huawei Health kit. The insertion of the steps seems to work well but I cannot see the sent values on the Huawei Health application. Is it normal ?

I have checked everything recommended on the current documentation and in the sample code.

  • The user is authenticated requesting scope permission Scopes.HEALTHKIT_STEP_BOTH
  • The Health kit is correctly configured on the console according to this page
  • The Health application on the device is up to date (version 10.1.2.553)
  • The latest SDK versions are integrated as: implementation "com.huawei.hms:health:5.0.3.300" and implementation "com.huawei.hms:hwid:5.0.3.301"

Below is the code I am using to send a value for test:

    // 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")
        }
    }
    

I clearly see the value is updated since in Logcat it prints

onSuccess update

I also read the the value using the read method on DataController and I was able to retrieve my data.

The questions I am asking myself are:

  • 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 ?
1

There are 1 answers

0
zhangxaochen On BEST ANSWER

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

Both in a local database and in Huawei Health Cloud.

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

Currently, Health Kit does not support to write the data directly into Health app and service. It will support to read fitness and health data in late October 2020, and it will support to write the data directly into Health app and service in January 2021.


Update:

You can check the latest version of Health Kit here. The checkHealthAppAuthorization and getHealthAppAuthorization APIs can be used to check whether the user has granted the HUAWEI Health app to open data to Health Kit.