404a 2024-03-24 11:21 采纳率: 0%
浏览 30

鸿蒙4.0ArkTs WantAgent的使用怎么报错


import notificationManager from '@ohos.notificationManager';
import wantAgent from '@ohos.app.ability.wantAgent';
import { WantAgent } from '@ohos.wantAgent';
import RdbStore from '../model/RdbStore';
import BatteryInfo from '../bean/BatteryInfo';

let intervalID;
export class GiveAnAlarm {

   wantAgentInstance: WantAgent

  async aboutToAppear(){
    let wantInfo: wantAgent.WantAgentInfo = {
      wants:[
        {
          bundleName:'com.example.aviationbatterytrackingsystem',
          abilityName:'EntryAbility',
        }
      ],
      requestCode:0,
      operationType:wantAgent.OperationType.START_ABILITIES,
      wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG]
    }
    this.wantAgentInstance =await wantAgent.getWantAgent(wantInfo)
  }


  //通知发生 告警信息
  public register() {
   intervalID = setInterval(function() {
      RdbStore.queryAlarmPromptAll((results: BatteryInfo[]) => {
        if(results.length >= 1){
          console.error("====告警信息:"+JSON.stringify(results))
          for(let i=0;i<results.length;i++){
            let notificationRequest: notificationManager.NotificationRequest = {
              id: Number(results[i].id),
              slotType: notificationManager.SlotType.SOCIAL_COMMUNICATION,
              content: {
                contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
                normal:{
                  title: '蓄电池追踪管理系统',
                  text: results[i].aircraftName+'蓄电池告警',
                }
              },
              deliveryTime:new Date().getTime(),
              showDeliveryTime:true,
              groupName:'wechat',
              wantAgent:this.wantAgentInstance
            };
            notificationManager.publish(notificationRequest);
          }
        }
      })
    }, 3000);
  }


  //退出定时任务
  public tsc(){
    clearInterval(intervalID);
  }




}

```******帮忙看看这是怎么回事*****
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/9c131226d2ec49a6ae726a568e7d843a.png "#left")




  • 写回答

3条回答 默认 最新

  • 码农阿豪@新空间 新星创作者: 前端开发技术领域 2024-03-24 11:22
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    这段代码是给一个功能类GiveAnAlarm,其中有两个方法aboutToAppear和register。aboutToAppear方法是获取一个能力代理对象的实例,register方法是注册一个定时任务,定时查询告警信息并发布通知。 问题具体是什么,并没有给出。如果需要帮助,需要描述清楚具体问题。 样例代码说明了如何使用wantAgent和notificationManager发布通知,以及如何使用RdbStore查询数据库。可参考样例代码实现类似的功能。
    评论

报告相同问题?

问题事件

  • 创建了问题 3月24日