Location>code7788 >text

【FAQ】HarmonyOS SDK closed source open capability —Health Service Kit

Popularity:589 ℃/2025-04-17 11:29:49

1. Problem description:

Call the healthStore API according to the official documentation to apply for user authorization; there is a pop-up window that pulls up, but there is no callback, and there is no callback when checking the permission interface.

Solution:

1. Before calling the interface, you need to use the init method for initialization. If there is no callback, please confirm whether the init method has been called.

/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section1571935817328

2. The number of steps is opened through daily activity data. If you need to obtain step data, you need to apply for "Daily Activity Data" permission.

3. You can also refer to the official example code for the application:/harmonyos_samples/health_-service_-kit_-sample-code

2. Problem description:

DailyActivities DailyActivities DailyActivities Sampling Data Field List. How to use this interface to obtain the user's steps?

Solution:

To obtain the steps, you need to apply for daily activity sampling data permissions in the Health Service Kit alliance card. See the permission description:/consumer/cn/doc/harmonyos-guides-V5/health-permission-description-V5

After the permission application is approved, the step data can be obtained through the following interface under the premise of user authorization:

1. You can obtain detailed step data through the interface;

readData:/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section193411928192218

2. You can obtain step statistics through the interface;

aggregateData:/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section4878142184216

3. You can query real-time step data by reading the real-time three-ring data interface;

readActivityReport:/consumer/cn/doc/harmonyos-references-V5/health-api-healthservice-V5#section9432058162017

For example interface call, please refer to sampleCode:/harmonyos_samples/health_-service_-kit_-sample-code/tree/master

3. Problem description:

I applied for health exercise permissions, but I have authorized it.DATA_TYPE has been authorized, but I still can't query this permission when I query this permission. I don't know if the permission I applied for is this permission.

Solution:

According to AppID: 109912713 query, permissions have been applied.

Please follow the following steps to troubleshoot:

1. Please check whether the client_id configured in module.json5 is: 109912713.

See "Configuring Client ID Guide" for the path:/consumer/cn/doc/harmonyos-guides-V5/health-configuration-client-id-V5

2. First call the "Unauthorization Interface" to cancel the authorization, then call the user authorization interface to re-authorize the user. Please confirm whether you have the permission to add ".DATA_TYPE" when authorizing;

See:/consumer/cn/doc/harmonyos-guides-V5/health-add-permissions-V5#section125616501171

User authorization:/consumer/cn/doc/harmonyos-guides-V5/health-add-permissions-V5#section0247115178

3. After the user checks permissions and authorizes, call the query authorization interface again to see;

Query permissions:/consumer/cn/doc/harmonyos-guides-V5/health-add-permissions-V5#section2932421571

4. If the problem still exists, please provide detailed logs that have not been filtered. You can execute the following command to obtain:

  1. Execution: hdc hilog >

  2. Trigger positioning

  3. Stop script execution.

  4. Get log information in the directory.

/******/

Supplement: The call to "Unauthorization Interface" is to refresh the permission cache, and this problem may be caused by the cache;

4. Problem description:

After applying for health permissions, the relevant permissions cannot be checked after authorization

I have applied for health exercise permissions. After the application authorization readDataTypes: [.DATA_TYPE], I will confirm that after the relevant pop-up window appears, then call the query permission api, but the query result is empty. I would like to ask if our current application readDataTypes: [.DATA_TYPE is successfully applied?

Solution:

Cause analysis:

1. Query the permission interface. The result will be returned only if the application has been applied and the user has authorized it.

2. DATA_TYPE is exercise record. The current application has not applied for exercise record permissions, so when querying exercise record permissions, no result value returns;

Handling suggestions:

1. Please check the client_id configured in the module.json5 file to whether you have permission to apply for exercise record in the alliance card;

For the configured client_id location information, please see the "Configure Client ID" guide:/consumer/cn/doc/harmonyos-guides-V5/health-configuration-client-id-V5

2. If you need to use exercise record permissions, please apply for exercise record permissions for the current application in the alliance card. Please refer to the "Apply for Exercise and Health Service" guide for application:

/consumer/cn/doc/harmonyos-guides-V5/health-apply-V5

3. If the developer needs to use and authorize daily activity data permissions, the daily activity permissions should be used: .DATA_TYPE

See the permission description for details:/consumer/cn/doc/harmonyos-guides-V5/health-permission-description-V5

Daily activity data permissions can query user step information. Under the premise of user authorization, step data can be obtained through the following interface:

1) The detailed step data can be obtained through the interface (data timeliness: 10 minutes level);

readData:/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section193411928192218

2) The step statistics can be obtained through the interface (data timeliness: 10 minutes level);

aggregateData:/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section4878142184216

3) You can query real-time step data by reading the real-time three-ring data interface;

readActivityReport:/consumer/cn/doc/harmonyos-references-V5/health-api-healthservice-V5#section9432058162017

For an example interface call, please refer to this sampleCode:/harmonyos_samples/health_-service_-kit_-sample-code/tree/master

5. Problem description:

When calling this API here to obtain exercise data, using the newly registered Huawei account or this account does not call this interface in the application fingerprint, it will report a 201 error. It is OK to use the previous Huawei account added to the application fingerprint. This error will also occur when you are officially packaged online.

Solution:

1. Before calling the readActivityReport interface, you need to complete the following steps:

1) Complete the application for sports and health services and configure the Client ID.

2) You must first guide the user authorization through the user authorization interface, and the user authorizes the daily activity data type reading permission (refer to the permission description) before you have the permission to read real-time three-ring data.

For details, please refer to the "Reading Real-time Three-ring Data" guide:/consumer/cn/doc/atomic-guides-V5/health-three-ring-read-as-V5#section056221011249

2. Error code 201 is a failure in authentication.

Possible Causes

1. The application fingerprint configuration is incorrect.

2. Lack of permissions.

3. Some interfaces can only be called by whitelisted users.

4. The number of test users has reached the upper limit.

Processing steps

1. Check the fingerprint certificate applied on the AGC. For details, please see Add Public Key Fingerprint.

2. Refer to the management user authorization to confirm that the user has authorized the relevant permissions.

3. If the user fails to apply to become a test user, please refer to the application verification as soon as possible to obtain official permissions and complete the application acceptance of the management desk.

For details, see "201 Authentication Failed":/consumer/cn/doc/harmonyos-references-V5/health-api-error-code-V5#section383228112410