The HUAWEI Health app may fail to synchronize data to the cloud in a timely manner. As a result, your app may not obtain the user's latest health and fitness data from the Health Service Kit cloud promptly. To address this issue, we allow users to manually trigger data synchronization once your app obtains their authorization.
To apply for the required scopes, go to Data Synchronization > Manual Data Synchronization on the Console of HUAWEI Developers.
| Scope | Description |
|---|---|
| https://www.huawei.com/healthkit/huaweihealthdata.cloudsync | Allows HUAWEI Health to synchronize personal data to the cloud (based on data synchronization settings in HUAWEI Health). |
This scope is available only to enterprise developer accounts.
| API | Description |
|---|---|
| syncAll(): Promise<void> | Synchronizes data as proactively triggered by the user. |
Complete the operations in Applying for Health Service Kit and Configuring the Client ID.
Before calling an API for the first time, call the init method to perform initialization.
Use the API for requesting user authorization to guide the user to grant authorization. For details, please refer to the scopes parameter in AuthorizationRequest. Call the manual data synchronization API after the user has authorized data synchronization.
For details about error codes, please refer to ArkTS API Error Codes. For FAQs, please refer to FAQs About Health Service Kit.
Import the Health Service Kit functional module and related public modules.
import { healthStore } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit'; Call syncAll to synchronize data and process the returned result.
try {
await healthStore.syncAll();
hilog.info(0x0000, 'testTag', 'Succeeded in synchronizing data.');
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to synchronize data. Code: ${err.code}, message: ${err.message}`);
}