HarmonyOS 读取用户的锻炼记录 报错code码201
Health Service kit 读取用户的锻炼记录 报错code码201
AsyncInvokeStub throw error: {“code”:201,“message”:“Permission verification failed, The app does not have WORKOUT detail read permission.”,“name”:“HealthKitError”}
授权也授权了读取walking 的权限
操作步骤:
1、
export class AuthManagement {
public static async auth(context: common.UIAbilityContext): Promise<boolean> {
try {
let authorizationParameter: healthStore.AuthorizationRequest = {
readDataTypes: [healthStore.exerciseSequenceHelper.DATA_TYPE],
writeDataTypes: [healthStore.exerciseSequenceHelper.DATA_TYPE]
}
let res: healthStore.AuthorizationResponse =
await healthStore.requestAuthorizations(context, authorizationParameter);
let grantedWriteDataTypes: healthStore.DataType[] = res.writeDataTypes;
let grantedReadDataTypes: healthStore.DataType[] = res.readDataTypes;
Logger.error(`Health=auth=try==>${JSON.stringify(res)}`)
return true;
} catch (err) {
Logger.error(`Health=auth=catch==>${JSON.stringify(err)}`)
return false;
}
}
}
2、
export class HealthManager {
public static async readData(startTimeParam: number, endTimeParam: number): Promise<string> {
try {
const startTime = startTimeParam; // 2023-10-23 14:00:00
const endTime = endTimeParam; // 2023-10-23 14:30:00
// 2. 查询跑步记录
const sequenceReadRequest: healthStore.ExerciseSequenceReadRequest = {
startTime: startTime,
endTime: endTime,
exerciseType: healthStore.exerciseSequenceHelper.walking.EXERCISE_TYPE,
count: 1,
sortOrder: 1,
readOptions: {
withDetails: true,
}
};
healthStore.readData<healthStore.exerciseSequenceHelper.walking.Model>(sequenceReadRequest).then((value) => {
Logger.debug(`health=============>>>>>>>${value}`)
});
return 'readData success ';
} catch (err) {
return 'readData fail :\n' + JSON.stringify(err);
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
然后就出现AsyncInvokeStub throw error: {“code”:201,“message”:“Permission verification failed, The app does not have WORKOUT detail read permission.”,“name”:“HealthKitError”}
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS 获取用户的步数
1230浏览 • 2回复 待解决
HarmonyOS 联系人读取报201权限错误
798浏览 • 1回复 待解决
HarmonyOS 如何获取用户设置了哪些用户认证能力
1312浏览 • 1回复 待解决
HarmonyOS如何获取用户相册所有目录?
3088浏览 • 1回复 待解决
使用FilePick上传uri失败,报错201
2485浏览 • 1回复 待解决
HarmonyOS 如何获取用户所在省市区?
1783浏览 • 1回复 待解决
如何获取用户设备的自定义名字?
272浏览 • 0回复 待解决
HarmonyOS 如何获取用户设备系统字体信息?
1324浏览 • 1回复 待解决
使用Account Kit 获取用户头像昵称
1183浏览 • 1回复 待解决
后台长时任务启动失败报错码201
3400浏览 • 1回复 待解决
HarmonyOS 安装报错code: 9568332
1459浏览 • 1回复 待解决
HarmonyOS如何从对话框获取用户返回结果?
1200浏览 • 1回复 待解决
HarmonyOS 如何实现获取用户头像保存到系统相册
1418浏览 • 1回复 待解决
取消Account Kit 获取用户头像昵称授权
1410浏览 • 1回复 待解决
#鸿蒙通关秘籍#如何获取用户桌面目录路径?
809浏览 • 1回复 待解决
是否可以获取用户手机上所有的app列表
1375浏览 • 1回复 待解决
安装报错verify code signature failed, code: 9568393
4088浏览 • 1回复 待解决
HarmonyOS 如何使用BusinessError设置code码并抛出异常?
1180浏览 • 1回复 待解决
HarmonyOS 如何获取用户相应权限,如通知权限、位置权限等
1367浏览 • 1回复 待解决
鸿蒙中关于定位扩展Ability是否可以获取用户的位置?
732浏览 • 0回复 待解决
HarmonyOS checkSysIntegrity 返回201
793浏览 • 1回复 待解决
HarmonyOS hap安装报错 code:9568305
1092浏览 • 1回复 待解决
HarmonyOS 安装APP报错code:9568289
2194浏览 • 1回复 待解决
从报错信息上分析,是应用权限的问题,请参考如下文档确认权限设置是正确的:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-service-kit-guide-V5