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}`);
  }
}
  • 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.

运行后

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.
  • 1.
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
859浏览 • 1回复 待解决
HarmonyOS catch error问题
843浏览 • 1回复 待解决
HarmonyOS ERROR: Invalid storeFile value
1120浏览 • 1回复 待解决
HarmonyOS 闪退报错 Error code:2100001
834浏览 • 1回复 待解决
HarmonyOS 获取push token error code 1000900010
799浏览 • 2回复 待解决