HarmonyOS backgroundTaskManager 9800005 Error

setBackgroundTask() {
  // 后台任务
  let wantAgentInfo: wantAgent.WantAgentInfo = {
    // 点击通知后,将要执行的动作列表
    wants: [
      {
        bundleName: "xxxx",
        abilityName: "EntryAbility"
      }
    ],
    // 点击通知后,动作类型
    actionType: wantAgent.OperationType.START_ABILITY,
    // 使用者自定义的一个私有值
    requestCode: 0,
    // 点击通知后,动作执行属性
    wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  };

  try {
    // 通过wantAgent模块下getWantAgent方法获取WantAgent对象
    wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
      try {
        backgroundTaskManager.startBackgroundRunning(this.context,
          backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback)
      } catch (error) {
        console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
      }
    });
  } catch (error) {
    console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
  }
}

运行后

07-29 13:08:35.060   6764-6764    A03D00/JSAPP  com.xxxx  E     Operation startBackgroundRunning failed. code is 9800005 message is BussinessError 9800005: Continuous Task verification failed. The bgMode is invalid.
HarmonyOS
2024-12-25 15:35:44
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

可以参考下错误文档,这边定位权限是否没有被使用或者没有在配置文件中配置,错误码参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/errorcode-backgroundtaskmgr-V5#section9800005-长时任务校验失败

长时任务参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/continuous-task-V5

分享
微博
QQ
微信
回复
2024-12-25 17:59:39
相关问题
HarmonyOS 长时任务启动失败9800005
124浏览 • 1回复 待解决
HarmonyOS catch error问题
412浏览 • 1回复 待解决
HarmonyOS ERROR: Invalid storeFile value
353浏览 • 1回复 待解决
HarmonyOS 闪退报错 Error code:2100001
237浏览 • 1回复 待解决
报错:Error while Deploying HAP。
12809浏览 • 2回复 待解决