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);
    }
  }
}

然后就出现AsyncInvokeStub throw error: {“code”:201,“message”:“Permission verification failed, The app does not have WORKOUT detail read permission.”,“name”:“HealthKitError”}

HarmonyOS
3天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

从报错信息上分析,是应用权限的问题,请参考如下文档确认权限设置是正确的:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/health-service-kit-guide-V5

分享
微博
QQ
微信
回复
3天前
相关问题
HarmonyOS取用户步数
70浏览 • 2回复 待解决
使用FilePick上传uri失败,报错201
1803浏览 • 1回复 待解决
HarmonyOS如何获取用户相册所有目录?
2192浏览 • 1回复 待解决
HarmonyOS 如何获取用户所在省市区?
406浏览 • 1回复 待解决
使用Account Kit 获取用户头像昵称
417浏览 • 1回复 待解决
后台长时任务启动失败报错201
2345浏览 • 1回复 待解决
HarmonyOS 安装报错code: 9568332
287浏览 • 1回复 待解决
取消Account Kit 获取用户头像昵称授权
617浏览 • 1回复 待解决
HarmonyOS hap安装报错 code:9568305
227浏览 • 1回复 待解决
HarmonyOS 安装APP报错code:9568289
1036浏览 • 1回复 待解决
HarmonyOS checkSysIntegrity 返回201
7浏览 • 1回复 待解决