写点什么

【FAQ】HarmonyOS SDK 闭源开放能力 —Health Service Kit

作者:HarmonyOS SDK
  • 2025-04-17
    贵州
  • 本文字数:2908 字

    阅读完需:约 10 分钟

1.问题描述:


按照官方文档调用 healthStore API 申请用户授权;有拉起授权弹窗,但是无回调,检查权限接口也无回调。


解决方案:


1、接口调用前,需先使用 init 方法进行初始化,没有回调的问题请确认是否已调用 init 方法。


https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section1571935817328


2、步数通过日常活动数据进行开放,如果需要获取步数数据,需要申请“日常活动数据”权限。


3、应用也可以参考官方实例代码:https://gitee.com/harmonyos_samples/health_-service_-kit_-sample-code


2.问题描述:


DailyActivities 日常活动采样数据字段列表。怎么利用这个接口获取用户的步数?


解决方案:


获取步数需要先在 Health Service Kit 联盟卡片中申请日常活动采样数据权限,权限说明见:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-permission-description-V5


权限申请通过后,在用户授权的前提下,可以通过以下接口获取步数数据:


1、可以通过 healthStore.readData 接口获取步数明细数据;


readData:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section193411928192218


2、可以通过 healthStore.aggregateData 接口获取步数统计数据;


aggregateData:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section4878142184216


3、可以通过 workout.readActivityReport 读取实时三环数据接口,查询实时的步数数据;


readActivityReport:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/health-api-healthservice-V5#section9432058162017


接口调用示例可以参考 sampleCode:https://gitee.com/harmonyos_samples/health_-service_-kit_-sample-code/tree/master


3.问题描述:


申请了健康运动权限,但是在授权 healthStore.samplePointHelper.dailyActivities.DATA_TYPE 已经授权过了,但是在查询这个权限还是查询不到,目前申请的权限不知道是不是这个权限。


解决方案:


根据 AppID:109912713 查询,权限是已经申请了的。


请根据以下步骤进行排查下:


1、请检查 module.json5 中配置的 client_id 是否为:109912713。


路径见“配置 Client ID 指南”:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-configuration-client-id-V5


2、先调用“取消授权接口”取消授权后,再调用用户授权接口,重新进行用户授权,在授权时请确认是否有添加“healthStore.samplePointHelper.dailyActivities.DATA_TYPE”权限;


取消授权接口见:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-add-permissions-V5#section125616501171


用户授权:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-add-permissions-V5#section0247115178


3、用户勾选权限并授权后,重新调用查询授权接口看看;


查询权限:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-add-permissions-V5#section2932421571


4、如果问题依旧存在,请提供未做筛选的详细日志,可以执行以下命令获取:


  1. 执行:hdc hilog > xxxx.log

  2. 触发定位

  3. 停止脚本执行。

  4. 在目录下获取日志信息。


/******/


补充:调用“取消授权接口”是为了刷新权限缓存,此问题可能是缓存原因导致的;


4.问题描述:


健康权限申请权限授权后查询不到相关权限


已经申请过健康运动权限,在应用授权 readDataTypes: [healthStore.exerciseSequenceHelper.DATA_TYPE],出现相关弹窗后确定再去调用查询权限 api,但是查询的结果是空的,想问下是不是我们当前应用 readDataTypes: [healthStore.exerciseSequenceHelper.DATA_TYPE 是否申请成功?


解决方案:


原因分析:


1、查询权限接口,只有在应用已申请,且用户已授权的情况下,才会返回结果。


2、healthStore.exerciseSequenceHelper.DATA_TYPE 是锻炼记录,当前应用未申请锻炼记录权限,故查询锻炼记录权限时无结果值返回;


处理建议:


1、请检查 module.json5 文件中配置的 client_id,是否有在联盟卡片中申请锻炼记录权限;


配置的 client_id 位置信息,请查看“配置 Client ID”指南:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-configuration-client-id-V5


2、如果需要使用锻炼记录权限,请在联盟卡片中为当前应用申请锻炼记录权限,申请指南请见“申请运动健康服务”指南:


https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-apply-V5


3、如果开发者需要使用并授权日常活动数据权限,应使用日常活动权限:samplePointHelper.dailyActivities.DATA_TYPE


详见权限说明:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-permission-description-V5


日常活动数据权限可以查询用户步数信息,在用户授权的前提下,可以通过以下接口获取步数数据:


1)可以通过 healthStore.readData 接口获取步数明细数据(数据及时性:10 分钟级);


readData:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section193411928192218


2)可以通过 healthStore.aggregateData 接口获取步数统计数据(数据及时性:10 分钟级);


aggregateData:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/health-api-healthstore-V5#section4878142184216


3)可以通过 workout.readActivityReport 读取实时三环数据接口,查询实时的步数数据;


readActivityReport:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/health-api-healthservice-V5#section9432058162017


接口调用示例可以参考此 sampleCode:https://gitee.com/harmonyos_samples/health_-service_-kit_-sample-code/tree/master


5.问题描述:


运动与健康这里调用 workout.readActivityReport 这个 api 去获取运动数据的时候,用刚注册的华为账号或者这个账号不在应用指纹里调用这个接口会报一个 201 的错误,用之前的添加到应用指纹的华为账号是可以的,这种在线上正式包的时候也会出现这个错误


解决方案:


1、调用 readActivityReport 接口前,需要完成以下步骤:


1)完成申请运动健康服务与配置 Client ID。


2)需先通过用户授权接口引导用户授权,用户授权日常活动数据类型读权限(参考权限说明)后,才有权限读取实时三环数据。


详见“读取实时三环数据”指南:https://developer.huawei.com/consumer/cn/doc/atomic-guides-V5/health-three-ring-read-as-V5#section056221011249


2、错误码 201 是鉴权失败。


可能原因


1、应用指纹配置不正确。


2、缺少权限。


3、部分接口仅白名单用户可调用。


4、测试用户数已达上限。


处理步骤


1、检查 AGC 上应用的指纹证书,详情请见添加公钥指纹。


2、参考管理用户授权,确认用户已授权相关权限。


3、用户申请成为测试用户失败,请尽快参考申请验证获取正式权限,完成管理台应用验收。


详见“201 鉴权失败”:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/health-api-error-code-V5#section383228112410

用户头像

HarmonyOS SDK

关注

HarmonyOS SDK 2022-06-16 加入

HarmonyOS SDK通过将HarmonyOS系统级能力对外开放,支撑开发者高效打造更纯净、更智能、更精致、更易用的鸿蒙应用,和开发者共同成长。

评论

发布
暂无评论
【FAQ】HarmonyOS SDK 闭源开放能力 —Health Service Kit_harmoyos_HarmonyOS SDK_InfoQ写作社区