SDK API

设置调试模式 API(setDebug)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请在 AbilityStage(#onCreate) 里面调用
  • 请在 init 之前调用
  • 可选接口

接口定义

/** * debug log 设置,默认false * * @param debug true 为 debug,false 为非 debug */ setDebug(debug: boolean)
              
                  /**
     * debug log 设置,默认false
     *
     * @param debug truedebugfalse 为非 debug
     */
    setDebug(debug: boolean)

            
This code block in the floating window

代码示例

EPushInterface.setDebug(true)//启用 debug
              
              EPushInterface.setDebug(true)//启用 debug

            
This code block in the floating window

参数说明

  • debug 为 true 则会打印 debug 级别的日志,false 则只会打印 warning 级别以上的日志

配置EngageLab Appkey(setAppKey)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请在 AbilityStage(#onCreate) 里面调用
  • 请在 init 之前调用
  • 必须调用的接口

接口定义

/** * 设置appkey * * @param appKey 为平台的appkey */ setAppKey(appKey: string)
              
                  /**
     * 设置appkey
     *
     * @param appKey 为平台的appkey
     */
    setAppKey(appKey: string)

            
This code block in the floating window

代码示例

EPushInterface.setAppKey("你的appKey")
              
              EPushInterface.setAppKey("你的appKey")

            
This code block in the floating window

参数说明

  • appKey 需要从EngageLab控制台获取。

配置下载渠道(setChannel)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

动态配置 channel(程序包下载渠道)

  • channel 指明应用程序包的下载渠道,为方便分渠道统计,具体值由你自行定义,如华为应用市场等。
  • 请在 AbilityStage(#onCreate) 里面调用
  • 请在 init 之前调用
  • 必须调用的接口

接口定义

/** * 配置渠道 * * @param channel 渠道名称 */ setChannel(channel: string)
              
                  /**
     * 配置渠道
     *
     * @param channel 渠道名称
     */
    setChannel(channel: string)

            
This code block in the floating window

代码示例

EPushInterface.setChannel("渠道名称")
              
              EPushInterface.setChannel("渠道名称")

            
This code block in the floating window

参数说明

  • channel 用户业务自定义。

配置自定义信息缓存条数(setCustomMessageMaxCacheCount)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

此接口用于推送EngageLab自定义消息(不适用于通知消息),针对部分 APP 特殊业务场景;如:当您服务端发送了100条自定义消息给到某个用户时,基于业务特性或者您自身业务处理性能考虑,您仅仅希望处理和保存最新的10条,则可以使用此接口。

  • 请在 AbilityStage(#onCreate) 里面调用
  • 请在 init 之前调用

接口定义

/** * 配置自定义后台信息缓存条数 * * @param maxCacheCount 缓存条数 */ setCustomMessageMaxCacheCount(maxCacheCount: number)
              
                  /**
     * 配置自定义后台信息缓存条数
     *
     * @param maxCacheCount 缓存条数
     */
    setCustomMessageMaxCacheCount(maxCacheCount: number)

            
This code block in the floating window

代码示例

EPushInterface.setCustomMessageMaxCacheCount(2)
              
              EPushInterface.setCustomMessageMaxCacheCount(2)

            
This code block in the floating window

参数说明

  • maxCacheCount 缓存条数

控制通知权限申请方式(setUserRequestNotificationPermission)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

设置是否由开发者自己调用通知申请权限。当设置为true时,EngageLabSDK不会主动申请通知权限,开发者需要在自己的代码中手动申请通知权限;当设置为false时,EngageLabSDK会在初始化时自动申请通知权限。

  • 请在 AbilityStage(#onCreate) 里面调用
  • 请在 init 之前调用
  • 可选接口

接口定义

/** * 设置是否由用户自己调用通知申请权限 * @param applicationContext 应用上下文 * @param enable true: 用户自己调用通知申请权限, false: SDK调用通知申请权限(默认) */ setUserRequestNotificationPermission(applicationContext: common.ApplicationContext, enable: boolean)
              
                  /**
     * 设置是否由用户自己调用通知申请权限
     * @param applicationContext 应用上下文
     * @param enable true: 用户自己调用通知申请权限, false: SDK调用通知申请权限(默认)
     */
    setUserRequestNotificationPermission(applicationContext: common.ApplicationContext, enable: boolean)

            
This code block in the floating window

代码示例

// 设置用户自己调用通知申请权限 EPushInterface.setUserRequestNotificationPermission(this.context.getApplicationContext(), true) // 设置SDK调用通知申请权限(默认) EPushInterface.setUserRequestNotificationPermission(this.context.getApplicationContext(), false)
              
              // 设置用户自己调用通知申请权限
EPushInterface.setUserRequestNotificationPermission(this.context.getApplicationContext(), true)

// 设置SDK调用通知申请权限(默认)
EPushInterface.setUserRequestNotificationPermission(this.context.getApplicationContext(), false)

            
This code block in the floating window

参数说明

  • enable 为 true 表示设置开发者自己申请通知权限,为 false 表示EngageLabSDK申请通知权限(默认)

开启推送业务功能 API(init)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

EngageLab推送服务,调用了本 API 后,开启JPush 推送服务,将会开始收集上报SDK业务功能所必要的用户个人信息。

  • 启动时调用

接口定义

/** * 开启推送业务功能 * @param context 上下文 */ init(context: common.UIAbilityContext | common.AbilityStageContext)
              
                 /**
   * 开启推送业务功能
   * @param context 上下文
   */
    init(context: common.UIAbilityContext | common.AbilityStageContext)

            
This code block in the floating window

代码示例

EPushInterface.init(this.context)
              
              EPushInterface.init(this.context)

            
This code block in the floating window

参数说明

  • context 在AbilityStage中传 common.AbilityStageContext ,在UIAbility中传 common.UIAbilityContext

接口使用说明

  • 开发者如果主动调用了 init 方法,会开启JPush推送服务。
  • 考虑 APP 上线合规,开发者必须在APP用户同意了隐私政策,并且开发者确定为App用户开始提供推送服务后,再调用启用推送业务功能接口使用EngageLab服务。
  • 关于 APP 隐私政策建议和说明,具体可以参考 如何草拟合规的隐私政策

获取 RegistrationID(getRegistrationId)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请先init,否则调用无效

接口定义

/** * 反回注册的rid * */ getRegistrationId(): string
              
                  /**
     * 反回注册的rid
     *
     */
    getRegistrationId(): string

            
This code block in the floating window

代码示例

let rid = EPushInterface.getRegistrationId()
              
              let rid = EPushInterface.getRegistrationId()

            
This code block in the floating window

参数说明

清除 Token(clearToken)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

清除当前设备的推送 token,用于重新注册获取新的 token。

  • 请先init,否则调用无效

接口定义

/** * 清除 token */ clearToken()
              
                  /**
     * 清除 token
     */
    clearToken()

            
This code block in the floating window

代码示例

EPushInterface.clearToken()
              
              EPushInterface.clearToken()

            
This code block in the floating window

参数说明

设置回调接口(setCallBackMsg)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

这个接口是用来接收sdk数据的。如:注册结果,登陆结果,通知点击结果,设置标签别名操作结果等的回调。 接收类需要实现CallBackMsg接口,CallBackMsg功能可看代码例子。

  • 请在 AbilityStage(#onCreate) 里面调用
  • 请在 init 之前调用
  • 必须调用的接口

接口定义

/** * 监听回调事件和数据 * * @param callBackMsg */ setCallBackMsg(callBackMsg: CallBackMsg)
              
                  /**
     * 监听回调事件和数据
     *
     * @param callBackMsg 
     */
    setCallBackMsg(callBackMsg: CallBackMsg)

            
This code block in the floating window

代码示例

class MyCallBackMsg extends CallBackMsg { context: common.ApplicationContext constructor(co: common.ApplicationContext) { super(); this.context = co } /** * 注册成功后回调rid * @param registrationId 注册成功后回调rid */ onRegister(registrationId: string): void { hilog.info(0x0000, 'testTag', '%{public}s', 'onRegister registrationId:' + registrationId); this.context.eventHub.emit('jPush_event', "registrationId:" + registrationId); } /** * 长连接登陆 回调 * @param isConnected true:成功,false:失败 */ onConnected(isConnected: boolean): void { hilog.info(0x0000, 'testTag', '%{public}s', 'onConnected isConnected:' + isConnected); this.context.eventHub.emit('jPush_event', "isConnected:" + isConnected); } /** * 操作 tag 接口回调 * @param eTagMessage * export class ETagMessage { * sequence?: number //对应操作id,全局不要重复 * code?: number //0成功,ETagMessage.CODE_TIME_OUT超时 * op?: string * tags?: string[] //对应数据 * curr?: number //数据当前页数,页数从1开始 * total?: number //数据总页数 * msg?: string * validated?:boolean //checkTagBindState 查询tag是否存在 * } */ onTagOperatorResult(eTagMessage: ETagMessage): void { hilog.info(0x0000, 'testTag', '%{public}s', 'onTagOperatorResult ETagMessage:' + JSON.stringify(eTagMessage)); this.context.eventHub.emit('jPush_event', "onTagOperatorResult:" + JSON.stringify(eTagMessage)); } /** * 操作 Alias 接口回调 * @param eAliasMessage * export class EAliasMessage { * sequence?: number //对应操作id,全局不要重复 * code?: number //0成功,EAliasMessage.CODE_TIME_OUT超时 * op?: string * alias?: string //对应数据 * curr?: number * total?: number * msg?: string * } */ onAliasOperatorResult(eAliasMessage: EAliasMessage): void { hilog.info(0x0000, 'testTag', '%{public}s', 'onAliasOperatorResult eAliasMessage:' + JSON.stringify(eAliasMessage)); this.context.eventHub.emit('jPush_event', "onAliasOperatorResult:" + JSON.stringify(eAliasMessage)); } /** * 通知点击事件回调 * @param eMessage * * export class EMessage { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(开始支持的版本:EPush HarmonyOS SDK v1.0.0) * } */ onClickMessage(eMessage: EMessage) { hilog.info(0x0000, 'testTag', '%{public}s', 'onClickMessage eMessage:' + JSON.stringify(eMessage)); this.context.eventHub.emit('jPush_event', "onClickMessage:" + JSON.stringify(eMessage)); } /** * 通知到达事件回调(仅通过EngageLab通道下发通知会触发此函数,通过鸿蒙系统通道下发通知由设备系统处理,暂不支持回调) * 开始支持的版本:EPush HarmonyOS SDK v1.0.0 * @param eMessage * * export class EMessage { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(实际情况,此处获取到的值只有可能是1) * } */ onArrivedMessage(eMessage: EMessage) { hilog.info(0x0000, 'testTag', '%{public}s', 'onArrivedMessage eMessage:' + JSON.stringify(eMessage)); this.context.eventHub.emit('jPush_event', "onArrivedMessage:" + JSON.stringify(eMessage)); } /** * 通知在前台不展示功能生效时触发的事件回调 * 开始支持的版本:EPush HarmonyOS SDK v1.0.0 * @param eMessage * * export class EMessage { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道 * } */ onUnShowMessage(eMessage: EMessage) { hilog.info(0x0000, 'testTag', '%{public}s', 'onUnShowMessage eMessage:' + JSON.stringify(eMessage)); this.context.eventHub.emit('jPush_event', "onUnShowMessage:" + JSON.stringify(eMessage)); } /** * 自定义信息回调 * 回调一:冷启动调用sdk初始化后回调之前还没有回调的信息 * 回调二:app存活时会直接回调信息 * 想要触发自定义信息走厂商通道下发时回调,请关注接口「customMessageBackgroundData」说明,或查看集成指南的「配置自定义信息」说明。 * @param eCustomMessage * * export class ECustomMessage { * msgId?: string //通知id * title?: string //通知标题 * content?: string //通知内容 * contentType?: string //通知内容类型 * extras?: Record<string, Object> //通知自定义键值对 * ttl?: number //后台下发的信息过期时间,单位秒 * stime?: number //后台下发时间,毫秒 * channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(开始支持的版本:EPush HarmonyOS SDK v1.0.0) * } */ onCustomMessage(eCustomMessage: ECustomMessage) { hilog.info(0x0000, TAG, '%{public}s', 'onCustomMessage eCustomMessage:' + JSON.stringify(eCustomMessage)); this.context.eventHub.emit('jPush_event', "onCustomMessage:" + JSON.stringify(eCustomMessage)); } /** * 通知扩展消息回调 * 想要触发通知扩展消息走厂商通道下发时回调,请关注接口「extraMessageBackgroundData」、「receiveExtraDataMessage」说明,或查看集成指南的「配置通知扩展消息」说明。 * * @param eMessageExtra * * export class EMessageExtra { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * extraData?: string//通知扩展消息的自定义数据 * } */ onEMessageExtra(eme: EMessageExtra) { hilog.info(0x0000, TAG, '%{public}s', 'onEMessageExtra eme:' + JSON.stringify(eme)); this.context.eventHub.emit('jPush_event', "onEMessageExtra:" + JSON.stringify(eme)); } /** * VoIP呼叫消息回调 * 想要触发VoIP呼叫消息走厂商通道下发时回调,请关注接口「voIPMessageBackgroundData」说明,或查看集成指南的「配置推送VoIP呼叫消息」说明。 * * export class EMessageVoIP { * msgId?: string //通知id * extraData?: string //VoIP自定义数据 } * @param jmVoIP */ onEMessageVoIP(emVoIP: EMessageVoIP) { hilog.info(0x0000, TAG, '%{public}s', 'EMessageVoIP emVoIP:' + JSON.stringify(emVoIP)); this.context.eventHub.emit('jPush_event', "EMessageVoIP:" + JSON.stringify(emVoIP)); } /** * export class ECmdMessage { * cmd?: number //操作类型 * errorCode?: number //状态码 * msg?: string //内容 * extra?: Record<string, Object> * } * @param cmdMessage */ onCommandResult(cmdMessage: ECmdMessage) { hilog.info(0x0000, TAG, '%{public}s', 'onCommandResult cmdMessage:' + JSON.stringify(cmdMessage)); this.context.eventHub.emit('jPush_event', "onCommandResult:" + JSON.stringify(cmdMessage)); } } EPushInterface.setCallBackMsg(new MyCallBackMsg(this.context))
              
              class MyCallBackMsg extends CallBackMsg {
  context: common.ApplicationContext

  constructor(co: common.ApplicationContext) {
    super();
    this.context = co
  }

  /**
   * 注册成功后回调rid
   * @param registrationId 注册成功后回调rid
   */
  onRegister(registrationId: string): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onRegister registrationId:' + registrationId);
    this.context.eventHub.emit('jPush_event', "registrationId:" + registrationId);
  }

  /**
   * 长连接登陆 回调
   * @param isConnected true:成功,false:失败
   */
  onConnected(isConnected: boolean): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onConnected isConnected:' + isConnected);
    this.context.eventHub.emit('jPush_event', "isConnected:" + isConnected);
  }

  /**
   * 操作 tag 接口回调
   * @param eTagMessage
   * export class ETagMessage {
   * sequence?: number //对应操作id,全局不要重复
   * code?: number //0成功,ETagMessage.CODE_TIME_OUT超时
   * op?: string
   * tags?: string[] //对应数据
   * curr?: number //数据当前页数,页数从1开始
   * total?: number //数据总页数
   * msg?: string
   * validated?:boolean //checkTagBindState 查询tag是否存在
   * }
   */
  onTagOperatorResult(eTagMessage: ETagMessage): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onTagOperatorResult ETagMessage:' + JSON.stringify(eTagMessage));
    this.context.eventHub.emit('jPush_event', "onTagOperatorResult:" + JSON.stringify(eTagMessage));
  }

  /**
   * 操作 Alias 接口回调
   * @param eAliasMessage
   * export class EAliasMessage {
   * sequence?: number //对应操作id,全局不要重复
   * code?: number //0成功,EAliasMessage.CODE_TIME_OUT超时
   * op?: string
   * alias?: string //对应数据
   * curr?: number 
   * total?: number 
   * msg?: string
   * }
   */
  onAliasOperatorResult(eAliasMessage: EAliasMessage): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onAliasOperatorResult eAliasMessage:' + JSON.stringify(eAliasMessage));
    this.context.eventHub.emit('jPush_event', "onAliasOperatorResult:" + JSON.stringify(eAliasMessage));
  }

  /**
   * 通知点击事件回调
   * @param eMessage
   *
   * export class EMessage {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(开始支持的版本:EPush HarmonyOS SDK v1.0.0)
   * }
   */
  onClickMessage(eMessage: EMessage) {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onClickMessage eMessage:' + JSON.stringify(eMessage));
    this.context.eventHub.emit('jPush_event', "onClickMessage:" + JSON.stringify(eMessage));
  }
  
  /**
   * 通知到达事件回调(仅通过EngageLab通道下发通知会触发此函数,通过鸿蒙系统通道下发通知由设备系统处理,暂不支持回调)
   * 开始支持的版本:EPush HarmonyOS SDK v1.0.0
   * @param eMessage
   *
   * export class EMessage {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(实际情况,此处获取到的值只有可能是1)
   * }
   */
  onArrivedMessage(eMessage: EMessage) {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onArrivedMessage eMessage:' + JSON.stringify(eMessage));
    this.context.eventHub.emit('jPush_event', "onArrivedMessage:" + JSON.stringify(eMessage));
  }
  
  /**
   * 通知在前台不展示功能生效时触发的事件回调
   * 开始支持的版本:EPush HarmonyOS SDK v1.0.0
   * @param eMessage
   *
   * export class EMessage {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道
   * }
   */
  onUnShowMessage(eMessage: EMessage) {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onUnShowMessage eMessage:' + JSON.stringify(eMessage));
    this.context.eventHub.emit('jPush_event', "onUnShowMessage:" + JSON.stringify(eMessage));
  }
  
   /**
   * 自定义信息回调
   *  回调一:冷启动调用sdk初始化后回调之前还没有回调的信息
   *  回调二:app存活时会直接回调信息
   *  想要触发自定义信息走厂商通道下发时回调,请关注接口「customMessageBackgroundData」说明,或查看集成指南的「配置自定义信息」说明。
   * @param eCustomMessage
   *
   * export class ECustomMessage {
   *  msgId?: string //通知id
   *  title?: string //通知标题
   *  content?: string //通知内容
   *  contentType?: string //通知内容类型
   *  extras?: Record<string, Object> //通知自定义键值对
   *  ttl?: number //后台下发的信息过期时间,单位秒
   *  stime?: number //后台下发时间,毫秒
   *  channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(开始支持的版本:EPush HarmonyOS SDK v1.0.0)
   * }
   */
  onCustomMessage(eCustomMessage: ECustomMessage) {
    hilog.info(0x0000, TAG, '%{public}s', 'onCustomMessage eCustomMessage:' + JSON.stringify(eCustomMessage));
    this.context.eventHub.emit('jPush_event', "onCustomMessage:" + JSON.stringify(eCustomMessage));
  }
  
  /**
   * 通知扩展消息回调
   * 想要触发通知扩展消息走厂商通道下发时回调,请关注接口「extraMessageBackgroundData」、「receiveExtraDataMessage」说明,或查看集成指南的「配置通知扩展消息」说明。
   * 
   * @param eMessageExtra
   *
   * export class EMessageExtra {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * extraData?: string//通知扩展消息的自定义数据
   * }
   */
  onEMessageExtra(eme: EMessageExtra) {
    hilog.info(0x0000, TAG, '%{public}s', 'onEMessageExtra eme:' + JSON.stringify(eme));
    this.context.eventHub.emit('jPush_event', "onEMessageExtra:" + JSON.stringify(eme));
  }
  
  /**
   * VoIP呼叫消息回调
   * 想要触发VoIP呼叫消息走厂商通道下发时回调,请关注接口「voIPMessageBackgroundData」说明,或查看集成指南的「配置推送VoIP呼叫消息」说明。
   * 
   * export class EMessageVoIP {
   * msgId?: string //通知id
   * extraData?: string //VoIP自定义数据
   }
   * @param jmVoIP
   */
  onEMessageVoIP(emVoIP: EMessageVoIP) {
    hilog.info(0x0000, TAG, '%{public}s', 'EMessageVoIP emVoIP:' + JSON.stringify(emVoIP));
    this.context.eventHub.emit('jPush_event', "EMessageVoIP:" + JSON.stringify(emVoIP));
  }
  
   /**
   * export class ECmdMessage {
   * cmd?: number //操作类型
   * errorCode?: number //状态码
   * msg?: string //内容
   * extra?: Record<string, Object>
   * }
   * @param cmdMessage
   */
  onCommandResult(cmdMessage: ECmdMessage) {
    hilog.info(0x0000, TAG, '%{public}s', 'onCommandResult cmdMessage:' + JSON.stringify(cmdMessage));
    this.context.eventHub.emit('jPush_event', "onCommandResult:" + JSON.stringify(cmdMessage));
  }
}


EPushInterface.setCallBackMsg(new MyCallBackMsg(this.context))

            
This code block in the floating window

参数说明

  • callBackMsg: 接收sdk数据回调的类,需继承CallBackMsg接口

回调方法明细

注册结果回调(onRegister)

注册结果回调

接口定义
/** * 注册结果回调 * * @param registrationId rid */ onRegister(registrationId: string)
              
                  /**
     * 注册结果回调
     *
     * @param registrationId  rid   
     */		
    onRegister(registrationId: string)

            
This code block in the floating window

长连接状态回调(isConnected)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

接口定义
/** * 长连接是否连接成功 * * 在开启推送业务功能后会进行长连接,连接成功/失败均会回调此方法 * * @param isConnected 长连接是否连接成功,true为成功;false为失败 */ onConnected(isConnected: boolean)
              
                  /**
     * 长连接是否连接成功
     *
     * 在开启推送业务功能后会进行长连接,连接成功/失败均会回调此方法
     *
     * @param isConnected  长连接是否连接成功,true为成功;false为失败   
     */		
    onConnected(isConnected: boolean)

            
This code block in the floating window

通知点击事件回调(onClickMessage)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

接口定义
/** * 通知点击事件回调 export class EMessage { msgId?: string //通知id title?: string //通知标题 content?: string //通知内容 extras?: Record<string, Object> //自定义数据 channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(开始支持的版本:EPush HarmonyOS SDK v1.0.0) } * * @param eMessage */ onClickMessage(eMessage: EMessage)
              
                  /**
     * 通知点击事件回调
       export class EMessage {
       msgId?: string //通知id
       title?: string //通知标题
       content?: string //通知内容
       extras?: Record<string, Object> //自定义数据
       channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(开始支持的版本:EPush HarmonyOS SDK v1.0.0)
       }
     *
     * @param eMessage  
     */		
    onClickMessage(eMessage: EMessage)

            
This code block in the floating window

通知到达事件回调(onArrivedMessage)

开始支持的版本:EPush HarmonyOS SDK v1.0.0 说明:仅通过EngageLab通道下发通知会触发此函数,通过鸿蒙系统通道下发通知由设备系统处理,暂不支持回调

接口定义
/** * 通知到达事件回调 export class EMessage { msgId?: string //通知id title?: string //通知标题 content?: string //通知内容 extras?: Record<string, Object> //自定义数据 channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(实际情况,此处获取到的值只有可能是1) } * * @param eMessage */ onArrivedMessage(eMessage: EMessage)
              
                  /**
     * 通知到达事件回调
       export class EMessage {
       msgId?: string //通知id
       title?: string //通知标题
       content?: string //通知内容
       extras?: Record<string, Object> //自定义数据
       channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(实际情况,此处获取到的值只有可能是1)
       }
     *
     * @param eMessage  
     */		
    onArrivedMessage(eMessage: EMessage)

            
This code block in the floating window

通知在前台不展示功能回调(onUnShowMessage)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

接口定义
/** * 通知在前台不展示功能生效时触发的事件回调 export class EMessage { msgId?: string //通知id title?: string //通知标题 content?: string //通知内容 extras?: Record<string, Object> //自定义数据 channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道 } * * @param eMessage */ onUnShowMessage(eMessage: EMessage)
              
                  /**
     * 通知在前台不展示功能生效时触发的事件回调
       export class EMessage {
       msgId?: string //通知id
       title?: string //通知标题
       content?: string //通知内容
       extras?: Record<string, Object> //自定义数据
       channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道
       }
     *
     * @param eMessage  
     */		
    onUnShowMessage(eMessage: EMessage)

            
This code block in the floating window

交互事件回调(onCommandResult)

接口定义
/** * 交互事件回调 * @param cmdMessage * export class ECmdMessage { * public static readonly CMD_TOKEN = 10000 // token 注册回调(开始支持的版本:EPush HarmonyOS SDK v1.0.0) * * cmd?: number //操作事件 * errorCode?: number //0表示成功,其他为错误 * msg?: string //内容信息 * extra?: Record<string, Object> * } */ onCommandResult(cmdMessage: ECmdMessage);
              
                /**
   * 交互事件回调
   * @param cmdMessage
   * export class ECmdMessage {
   * public static readonly CMD_TOKEN = 10000 //	token 注册回调(开始支持的版本:EPush HarmonyOS SDK v1.0.0)
   *
   * cmd?: number  //操作事件
   * errorCode?: number //0表示成功,其他为错误
   * msg?: string //内容信息
   * extra?: Record<string, Object>
   * }
   */
  onCommandResult(cmdMessage: ECmdMessage);

            
This code block in the floating window
cmd errorCode msg DESCRIPTION
0 失败 code 失败信息 注册失败
2006 0 success onResume 设置回调
2007 0 success onStop 设置回调
1000 0/1 success/fail 获取token,0:成功,1:失败

后台自定义信息回调(onCustomMessage)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

接口定义
/** * 自定义信息通知回调 * 回调一:冷启动调用sdk初始化后回调之前还没有回调的信息 * 回调二:app存活时会直接回调信息 * 想要有自定义信息回调,还需查看集成指南的自定义信息集成配置方式 * @param eCustomMessage * * export class ECustomMessage { * msgId?: string //通知id * title?: string //通知标题 * content?: string //通知内容 * contentType?: string //通知内容类型 * extras?: Record<string, Object> //通知自定义键值对 * ttl?: number //后台下发的信息过期时间,单位秒 * stime?: number //后台下发时间,毫秒 * channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(开始支持的版本:EPush HarmonyOS SDK v1.0.0) * } */ onCustomMessage(eCustomMessage: ECustomMessage);
              
                /**
   * 自定义信息通知回调
   *  回调一:冷启动调用sdk初始化后回调之前还没有回调的信息
   *  回调二:app存活时会直接回调信息
   *  想要有自定义信息回调,还需查看集成指南的自定义信息集成配置方式
   * @param eCustomMessage
   *
   * export class ECustomMessage {
   *  msgId?: string //通知id
   *  title?: string //通知标题
   *  content?: string //通知内容
   *  contentType?: string //通知内容类型
   *  extras?: Record<string, Object> //通知自定义键值对
   *  ttl?: number //后台下发的信息过期时间,单位秒
   *  stime?: number //后台下发时间,毫秒
   *  channel?: number //数据来源通道 0:厂商通道 1:EngageLab通道(开始支持的版本:EPush HarmonyOS SDK v1.0.0)
   * }
   */
  onCustomMessage(eCustomMessage: ECustomMessage);

            
This code block in the floating window

通知扩展消息回调(onEMessageExtra)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

接口定义
/** * 通知扩展消息回调 * @param eMessageExtra * * export class EMessageExtra { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * extraData?: string//通知扩展消息的自定义数据 * } */ onEMessageExtra(eme: EMessageExtra);
              
                /**
   * 通知扩展消息回调
   * @param eMessageExtra
   *
   * export class EMessageExtra {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * extraData?: string//通知扩展消息的自定义数据
   * }
   */
  onEMessageExtra(eme: EMessageExtra);

            
This code block in the floating window

VoIP呼叫消息回调(onEMessageVoIP)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

接口定义
/** * VoIP呼叫消息回调 * export class EMessageVoIP { * msgId?: string //通知id * extraData?: string //VoIP自定义数据 } * @param emVoIP */ onEMessageVoIP(emVoIP: EMessageVoIP);
              
                 /**
   * VoIP呼叫消息回调
   * export class EMessageVoIP {
   * msgId?: string //通知id
   * extraData?: string //VoIP自定义数据
   }
   * @param emVoIP
   */
  onEMessageVoIP(emVoIP: EMessageVoIP);

            
This code block in the floating window

操作 tag 接口回调(onTagOperatorResult)

接口定义
/** * 操作 tag 接口回调 export class ETagMessage { sequence?: number //对应操作id,全局不要重复 code?: number //0成功,ETagMessage.CODE_TIME_OUT超时 op?: string tags?: string[] //对应数据 curr?: number //数据当前页数,页数从1开始 total?: number //数据总页数 msg?: string } * * @param eTagMessage */ onTagOperatorResult(eTagMessage: ETagMessage)
              
                 /**
    * 操作 tag 接口回调
      export class ETagMessage {
      sequence?: number //对应操作id,全局不要重复
      code?: number //0成功,ETagMessage.CODE_TIME_OUT超时
      op?: string
      tags?: string[] //对应数据
      curr?: number //数据当前页数,页数从1开始
      total?: number //数据总页数
      msg?: string
      }
    *
    * @param eTagMessage
   */
  onTagOperatorResult(eTagMessage: ETagMessage)

            
This code block in the floating window

操作 Alias 接口回调(onAliasOperatorResult)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

接口定义
/** * 操作 Alias 接口回调 export class EAliasMessage { sequence?: number //对应操作id,全局不要重复 code?: number //0成功,EAliasMessage.CODE_TIME_OUT超时 op?: string alias?: string //对应数据 curr?: number total?: number msg?: string } * * @param eAliasMessage */ onAliasOperatorResult(eAliasMessage: EAliasMessage)
              
                /**
   * 操作 Alias 接口回调
     export class EAliasMessage {
      sequence?: number //对应操作id,全局不要重复
      code?: number //0成功,EAliasMessage.CODE_TIME_OUT超时
      op?: string
      alias?: string //对应数据
      curr?: number
      total?: number
      msg?: string
     }
   *
   * @param eAliasMessage
   */
  onAliasOperatorResult(eAliasMessage: EAliasMessage)

            
This code block in the floating window

通知跳转数据接收(setClickWant)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

为了能接收到通知点击后回调的对应数据 在通知跳转页面UIAbility的onCreate、onNewWant中调用:传入want 然后会通过上面设置的回调接口CallBackMsg类中的onClickMessage方法回调

接口定义

/** * 在通知跳转页面UIAbility的onCreate、onNewWant中调用:传入want和context,通过上面的onClickMessage接口回调自定义数据 * * @param want UIAbility中的want * @param context 应用上下文,在UIAbility中传this.context,在AbilityStage中传context */ setClickWant(want: Want, context: common.ApplicationContext | common.AbilityStageContext): Promise<EMessage | undefined>
              
                 /**
   * 在通知跳转页面UIAbility的onCreate、onNewWant中调用:传入want和context,通过上面的onClickMessage接口回调自定义数据
   *
   * @param want UIAbility中的want
   * @param context 应用上下文,在UIAbility中传this.context,在AbilityStage中传context
   */
    setClickWant(want: Want, context: common.ApplicationContext | common.AbilityStageContext): Promise<EMessage | undefined>

            
This code block in the floating window

代码示例

onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { this.setClickWant(want) } onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { super.onNewWant(want, launchParam) this.setClickWant(want) } private async setClickWant(want: Want) { let j:EMessage|undefined = await EPushInterface.setClickWant(want, this.context); hilog.info(0x0000, TAG, '%{public}s', 'setClickWant: '+JSON.stringify(j)); }
              
              onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    this.setClickWant(want)
}

onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
  super.onNewWant(want, launchParam)
  this.setClickWant(want)
}

private async setClickWant(want: Want) {
    let j:EMessage|undefined = await EPushInterface.setClickWant(want, this.context);
    hilog.info(0x0000, TAG, '%{public}s', 'setClickWant: '+JSON.stringify(j));
}

            
This code block in the floating window

参数说明

  • want:为UIAbility中的want

  • context:应用上下文,在UIAbility中传 this.context,在AbilityStage中传 context

  • return

    • 反回数据,EMessage表示正确处理并反回了数据对象,undefined表示没有数据或不是EngageLab的数据或异常出错

停止通知(stopPush)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请先init,否则调用无效

接口定义

/** * 停止通知 * */ stopPush()
              
                  /**
     * 停止通知
     *
     */
    stopPush()

            
This code block in the floating window

代码示例

EPushInterface.stopPush()
              
              EPushInterface.stopPush()

            
This code block in the floating window

参数说明

恢复通知(resumePush)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请先init,否则调用无效

接口定义

/** * 恢复通知 * */ resumePush()
              
                  /**
     * 恢复通知
     *
     */
    resumePush()

            
This code block in the floating window

代码示例

EPushInterface.resumePush()
              
              EPushInterface.resumePush()

            
This code block in the floating window

参数说明

通知状态查询(isPushStopped)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请先init,否则调用无效

接口定义

/** * 通知状态查询 * */ isPushStopped(): boolean | undefined
              
                  /**
     * 通知状态查询
     *
     */
    isPushStopped(): boolean | undefined

            
This code block in the floating window

代码示例

let isPushStopped = EPushInterface.isPushStopped()
              
              let isPushStopped = EPushInterface.isPushStopped()

            
This code block in the floating window

参数说明

  • 反回值:true停止,false正常,undefined没有初始化等异常情况

标签与别名-api

新增标签(addTags)

功能说明

接口定义

/** * 增加指定tag,累加逻辑,之前设置的标签依然存在 * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性 * @param tags 标签数组,每个tag命名长度限制为40字节,最多支持设置1000个tag,且单次操作总长度不得超过5000字节 */ addTags(sequence: number, tags: string[])
              
                  /**
     * 增加指定tag,累加逻辑,之前设置的标签依然存在
     *
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性
     * @param tags     标签数组,每个tag命名长度限制为40字节,最多支持设置1000tag,且单次操作总长度不得超过5000字节
     */
    addTags(sequence: number, tags: string[])

            
This code block in the floating window

代码示例

EPushInterface.addTags(this.sequence++, ["ccc", "ddddd"])
              
              EPushInterface.addTags(this.sequence++, ["ccc", "ddddd"])

            
This code block in the floating window

参数说明

  • sequence
    • 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性。
  • tags
    • 每次调用至少新增一个 tag。
    • 有效的标签组成:字母(区分大小写)、数字、下划线、汉字、特殊字符 @!#$&*+=.|。
    • 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 1000 个 tag,且单次操作总长度不得超过 5000 字节。(判断长度需采用 UTF-8 编码) 单个设备最多支持设置 1000 个 tag。App 全局 tag 数量无限制。

删除标签(deleteTags)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

接口定义

/** * 删除指定tag,删除逻辑,会删除指定的标签 * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性 * @param tags 标签数组,每个tag命名长度限制为40字节,最多支持设置1000个tag,且单次操作总长度不得超过5000字节 */ deleteTags(sequence: number, tags: string[])
              
                  /**
     * 删除指定tag,删除逻辑,会删除指定的标签
     *
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性
     * @param tags     标签数组,每个tag命名长度限制为40字节,最多支持设置1000tag,且单次操作总长度不得超过5000字节
     */
    deleteTags(sequence: number, tags: string[])

            
This code block in the floating window

代码示例

EPushInterface.deleteTags(this.sequence++, ["ccc"])
              
                EPushInterface.deleteTags(this.sequence++, ["ccc"])

            
This code block in the floating window

参数说明

  • sequence
    • 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性。
  • tags
    • 每次调用至少删除一个 tag。
    • 有效的标签组成:字母(区分大小写)、数字、下划线、汉字、特殊字符 @!#$&*+=.|。
    • 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 1000 个 tag,且单次操作总长度不得超过 5000 字节。(判断长度需采用 UTF-8 编码) 单个设备最多支持设置 1000 个 tag。App 全局 tag 数量无限制。

设置标签(setTags)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

接口定义

/** * 更新指定tag,覆盖逻辑,之前添加的tag会清空 * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性 * @param tags 标签数组,每个tag命名长度限制为40字节,最多支持设置1000个tag,且单次操作总长度不得超过5000字节 */ setTags(sequence: number, tags: string[])
              
                  /**
     * 更新指定tag,覆盖逻辑,之前添加的tag会清空
     *
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性
     * @param tags     标签数组,每个tag命名长度限制为40字节,最多支持设置1000tag,且单次操作总长度不得超过5000字节
     */
    setTags(sequence: number, tags: string[])

            
This code block in the floating window

代码示例

EPushInterface.setTags(this.sequence++, ["xxx", "yyy"])
              
              EPushInterface.setTags(this.sequence++, ["xxx", "yyy"])

            
This code block in the floating window

参数说明

  • sequence
    • 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性。
  • tags
    • 每次调用至少新增一个 tag。
    • 有效的标签组成:字母(区分大小写)、数字、下划线、汉字、特殊字符 @!#$&*+=.|。
    • 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 1000 个 tag,且单次操作总长度不得超过 5000 字节。(判断长度需采用 UTF-8 编码) 单个设备最多支持设置 1000 个 tag。App 全局 tag 数量无限制。

查询指定标签的绑定状态(checkTagBindState)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

接口定义

/** * 查询指定tag * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性 * @param tag 标签,每个tag命名长度限制为40字节 */ checkTagBindState(sequence: number, tag: string)
              
                  /**
     * 查询指定tag
     * 
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性
     * @param tag      标签,每个tag命名长度限制为40字节
     */
    checkTagBindState(sequence: number, tag: string) 

            
This code block in the floating window

代码示例

EPushInterface.checkTagBindState(this.sequence++, "ccc")
              
               EPushInterface.checkTagBindState(this.sequence++, "ccc")

            
This code block in the floating window

参数说明

  • sequence
    • 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性。
  • tags
    • 被查询的 tag

清除所有标签(cleanTags)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

接口定义

/** * 删除所有tag,清空逻辑,会删除所有的标签 * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性 */ cleanTags(sequence: number)
              
                  /**
     * 删除所有tag,清空逻辑,会删除所有的标签
     *
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性
     */
    cleanTags(sequence: number)

            
This code block in the floating window

代码示例

EPushInterface.cleanTags(this.sequence++)
              
              EPushInterface.cleanTags(this.sequence++)

            
This code block in the floating window

参数说明

  • sequence
    • 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性。

查询所有标签(getTags)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

接口定义

/** * 查询所有tag,获取逻辑,会获取所有标签 * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性 * @param curr 获取当前的页数,开始页数值为1 */ getTags(sequence: number, curr: number)
              
                  /**
     * 查询所有tag,获取逻辑,会获取所有标签
     *
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性
     * @param curr  获取当前的页数,开始页数值为1
     */
    getTags(sequence: number, curr: number)

            
This code block in the floating window

代码示例

EPushInterface.getTags(this.sequence++, 1)
              
              EPushInterface.getTags(this.sequence++, 1)

            
This code block in the floating window

参数说明

  • sequence
    • 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性。

设置别名(setAlias)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

接口定义

/** * 设置alias * * 同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户 * * 不限定一个别名只能指定一个用户 * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性 * @param alias 有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符@!#$&*+=.|。限制:alias命名长度限制为 40 字节(判断长度需采用 UTF-8 编码) * */ setAlias(sequence: number, alias: string)
              
                  /**
     * 设置alias
     * 
     * 同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户
     * 
     * 不限定一个别名只能指定一个用户
     *
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性
     * @param alias    有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符@!#$&*+=.|。限制:alias命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)
     *                             
     */
    setAlias(sequence: number, alias: string)

            
This code block in the floating window

代码示例

EPushInterface.setAlias(this.sequence++, "gggdd")
              
               EPushInterface.setAlias(this.sequence++, "gggdd")

            
This code block in the floating window

参数说明

  • sequence
    • 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性,推荐每次都用不同的数字序号。
  • alias
    • 每次调用设置有效的别名,覆盖之前的设置。
    • 有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符 @!#$&*+=.|。
    • 限制:alias 命名长度限制为 40 字节。(判断长度需采用 UTF-8 编码)

查询别名(getAlias)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

接口定义

/** * 获取alias * * 同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户 * * 不限定一个别名只能指定一个用户 * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性 */ getAlias(sequence: number)
              
                  /**
     * 获取alias
     * 
     * 同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户
     * 
     * 不限定一个别名只能指定一个用户
     *
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性
     */
    getAlias(sequence: number)

            
This code block in the floating window

代码示例

EPushInterface.getAlias(this.sequence++)
              
              EPushInterface.getAlias(this.sequence++)

            
This code block in the floating window

参数说明

  • sequence
    • 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性,推荐每次都用不同的数字序号。

删除别名(deleteAlias)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

接口定义

/** * 清除alias * * 同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户 * * 不限定一个别名只能指定一个用户 * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性 */ deleteAlias(sequence: number)
              
                  /**
     * 清除alias
     *
     * 同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户
     * 
     * 不限定一个别名只能指定一个用户
     *
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性
     */
    deleteAlias(sequence: number)

            
This code block in the floating window

代码示例

EPushInterface.deleteAlias(this.sequence++)
              
              EPushInterface.deleteAlias(this.sequence++)

            
This code block in the floating window

参数说明

  • sequence
    • 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性,推荐每次都用不同的数字序号。

设置 TCP SSL(setTcpSSl)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

设置是否使用 TCP SSL 加密连接。

  • 请在 init 之前调用
  • 可选接口

接口定义

/** * 设置 TCP SSL * @param b true: 使用 SSL 加密, false: 不使用 SSL 加密 */ setTcpSSl(b: boolean)
              
                  /**
     * 设置 TCP SSL
     * @param b true: 使用 SSL 加密, false: 不使用 SSL 加密
     */
    setTcpSSl(b: boolean)

            
This code block in the floating window

代码示例

EPushInterface.setTcpSSl(true) // 启用 SSL 加密
              
              EPushInterface.setTcpSSl(true) // 启用 SSL 加密

            
This code block in the floating window

参数说明

  • b 为 true 表示使用 TCP SSL 加密连接,为 false 表示不使用 SSL 加密

设置心跳周期(setHeartbeatTime)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

设置长连接心跳周期,用于保持连接活跃。

  • 可选接口

接口定义

/** * 设置长连接心跳周期 * @param heartbeatTime 单位秒,范围[30,290] */ setHeartbeatTime(heartbeatTime: number)
              
                  /**
     * 设置长连接心跳周期
     * @param heartbeatTime 单位秒,范围[30,290]
     */
    setHeartbeatTime(heartbeatTime: number)

            
This code block in the floating window

代码示例

EPushInterface.setHeartbeatTime(60) // 设置心跳周期为 60 秒
              
              EPushInterface.setHeartbeatTime(60) // 设置心跳周期为 60
            
This code block in the floating window

参数说明

  • heartbeatTime 心跳周期,单位秒,取值范围为 30 到 290 秒

设置角标(setBadgeNumber)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请先init,否则调用无效

接口定义

/** * 设置角标 * * @param badgeNumber 角标值 */ setBadgeNumber(badgeNumber: number)
              
                  /**
     * 设置角标
     *
     * @param badgeNumber 角标值
     */
    setBadgeNumber(badgeNumber: number)

            
This code block in the floating window

代码示例

EPushInterface.setBadgeNumber(0)
              
                EPushInterface.setBadgeNumber(0)

            
This code block in the floating window

参数说明

  • badgeNumber
    • 角标值

自定义信息接收(customMessageBackgroundData)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 此函数仅处理自定义消息走鸿蒙下发的场景,如果业务用到自定义消息,请务必按照集成指南文档中:配置自定义信息进行操作

接口定义

/** * 自定义消息集成使用 * 后台自定义信息接收 * @param data BACKGROUND消息 */ customMessageBackgroundData(data: pushCommon.PushPayload): Promise<boolean>
              
                  /**
     * 自定义消息集成使用
     * 后台自定义信息接收
     * @param data BACKGROUND消息
     */
    customMessageBackgroundData(data: pushCommon.PushPayload): Promise<boolean>

            
This code block in the floating window

代码示例

import { UIAbility } from '@kit.AbilityKit'; import { EPushInterface } from '@engagelab/push'; import { pushCommon, pushService } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'ENGAGELAB-JLog-PushMessageAbility' export default class PushMessageAbility extends UIAbility { onCreate(): void { try { // receiveMessage中的参数固定为BACKGROUND-------后台自定义信息接收 pushService.receiveMessage('BACKGROUND', this, async (data: pushCommon.PushPayload) => { let jg = await EPushInterface.customMessageBackgroundData(data) if (jg) { //如果是true为已经处理 return } }); } catch (e) { hilog.info(0x0000, TAG, '%{public}s', 'BACKGROUND fail:'+JSON.stringify(e)); } }
              
              import { UIAbility } from '@kit.AbilityKit';
import { EPushInterface } from '@engagelab/push';
import { pushCommon, pushService } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const TAG: string = 'ENGAGELAB-JLog-PushMessageAbility'
export default class PushMessageAbility extends UIAbility {
  onCreate(): void {
    try { // receiveMessage中的参数固定为BACKGROUND-------后台自定义信息接收
      pushService.receiveMessage('BACKGROUND', this, async (data: pushCommon.PushPayload) => {
        let jg = await EPushInterface.customMessageBackgroundData(data)
        if (jg) { //如果是true为已经处理
          return
        }
      });
    } catch (e) {
      hilog.info(0x0000, TAG, '%{public}s', 'BACKGROUND fail:'+JSON.stringify(e));
    }
}

            
This code block in the floating window

参数说明

  • data
    • receiveMessage中的参数固定为BACKGROUND数据,即后台数据
  • return
    • 反回数据,true表示正确处理了,false表示不是EngageLab的数据或异常出错

VoIP呼叫消息接收(voIPMessageBackgroundData)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 此函数仅处理VoIP呼叫消息走鸿蒙下发的场景,如果业务用到VoIP呼叫消息,请务必按照集成指南文档中:配置推送VoIP呼叫消息进行操作

接口定义

/** * VoIP呼叫消息集成使用 * VoIP呼叫消息接收 * @param data VoIP消息 */ voIPMessageBackgroundData(data: pushCommon.PushPayload): Promise<boolean>
              
                  /**
     * VoIP呼叫消息集成使用
     * VoIP呼叫消息接收
     * @param data VoIP消息
     */
    voIPMessageBackgroundData(data: pushCommon.PushPayload): Promise<boolean>

            
This code block in the floating window

代码示例

import { UIAbility } from '@kit.AbilityKit'; import { EPushInterface } from '@engagelab/push'; import { pushCommon, pushService } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'ENGAGELAB-JLog-PushMessageAbility' export default class PushMessageAbility extends UIAbility { onCreate(): void { try { pushService.receiveMessage('VoIP', this, async (data) => { let jg = await EPushInterface.voIPMessageBackgroundData(data) if (jg) { //如果是true为已经处理 return } }); } catch (e) { hilog.info(0x0000, TAG, '%{public}s', 'VoIP fail:'+JSON.stringify(e)); } } }
              
              import { UIAbility } from '@kit.AbilityKit';
import { EPushInterface } from '@engagelab/push';
import { pushCommon, pushService } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const TAG: string = 'ENGAGELAB-JLog-PushMessageAbility'
export default class PushMessageAbility extends UIAbility {
  onCreate(): void {
    try {
      pushService.receiveMessage('VoIP', this, async (data) => {
        let jg = await EPushInterface.voIPMessageBackgroundData(data)
        if (jg) { //如果是true为已经处理
          return
        }
      });
    } catch (e) {
      hilog.info(0x0000, TAG, '%{public}s', 'VoIP fail:'+JSON.stringify(e));
    }
  }


}

            
This code block in the floating window

参数说明

  • data
    • receiveMessage中的参数固定为VoIP数据,即通VoIP呼叫消息
  • return
    • 反回数据,true表示正确处理了,false表示不是EngageLab的数据或异常出错

通知扩展消息接收--进程存活时(extraMessageBackgroundData)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 此函数仅处理通知扩展消息走鸿蒙下发的场景,如果业务用到通知扩展消息,请务必按照集成指南文档中:配置通知扩展消息进行操作

接口定义

/** * 通知扩展消息集成使用 * 通知扩展消息接收 * @param data IM消息 */ extraMessageBackgroundData(data: pushCommon.PushPayload): Promise<boolean>
              
                  /**
     * 通知扩展消息集成使用
     * 通知扩展消息接收
     * @param data IM消息
     */
    extraMessageBackgroundData(data: pushCommon.PushPayload): Promise<boolean>

            
This code block in the floating window

代码示例

import { UIAbility } from '@kit.AbilityKit'; import { EPushInterface } from '@engagelab/push'; import { pushCommon, pushService } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'ENGAGELAB-JLog-PushMessageAbility' export default class PushMessageAbility extends UIAbility { onCreate(): void { try { // receiveMessage中的参数固定为IM-------拓展通知接收 pushService.receiveMessage('IM', this, async (data) => { let jg = await EPushInterface.extraMessageBackgroundData(data) if (jg) { //如果是true为已经处理 return } }); } catch (e) { hilog.info(0x0000, TAG, '%{public}s', 'IM fail:'+JSON.stringify(e)); } }
              
              import { UIAbility } from '@kit.AbilityKit';
import { EPushInterface } from '@engagelab/push';
import { pushCommon, pushService } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const TAG: string = 'ENGAGELAB-JLog-PushMessageAbility'
export default class PushMessageAbility extends UIAbility {
  onCreate(): void {
    try { // receiveMessage中的参数固定为IM-------拓展通知接收
      pushService.receiveMessage('IM', this, async (data) => {
        let jg = await EPushInterface.extraMessageBackgroundData(data)
        if (jg) { //如果是true为已经处理
          return
        }
      });
    } catch (e) {
      hilog.info(0x0000, TAG, '%{public}s', 'IM fail:'+JSON.stringify(e));
    }
}

            
This code block in the floating window

参数说明

  • data
    • receiveMessage中的参数固定为IM数据,即通知扩展消息
  • return
    • 反回数据,true表示正确处理了,false表示不是EngageLab的数据或异常出错

通知扩展消息接收--进程不存在(receiveExtraDataMessage)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 此函数仅处理通知扩展消息走鸿蒙下发的场景,如果业务用到通知扩展消息,请务必按照集成指南文档中:配置通知扩展消息进行操作

接口定义

/** * 通知扩展消息集成使用 * 通知扩展消息接收 * @param rNEAbility 对应RemoteNotificationExtensionAbility * @param data onReceiveMessage数据 */ receiveExtraDataMessage(rNEAbility: RemoteNotificationExtensionAbility, remoteNotificationInfo: pushCommon.RemoteNotificationInfo): Promise<EMessageExtra | undefined>
              
                  /**
     * 通知扩展消息集成使用
     * 通知扩展消息接收
     * @param rNEAbility 对应RemoteNotificationExtensionAbility
     * @param data onReceiveMessage数据
     */
    receiveExtraDataMessage(rNEAbility: RemoteNotificationExtensionAbility, remoteNotificationInfo: pushCommon.RemoteNotificationInfo): Promise<EMessageExtra | undefined>

            
This code block in the floating window

代码示例

import { pushCommon, RemoteNotificationExtensionAbility } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { EPushInterface } from '@engagelab/push'; const TAG: string = 'ENGAGELAB-JLog-RemoteNotificationExtAbility' export default class RemoteNotificationExtAbility extends RemoteNotificationExtensionAbility { async onReceiveMessage(remoteNotificationInfo: pushCommon.RemoteNotificationInfo): Promise<pushCommon.RemoteNotificationContent> { hilog.info(0x0000, TAG, 'onReceiveMessage, remoteNotificationInfo: %{public}s', JSON.stringify(remoteNotificationInfo)); let eMessageExtra = await EPushInterface.receiveExtraDataMessage(this, remoteNotificationInfo); hilog.info(0x0000, TAG, 'onReceiveMessage eMessageExtra:' + JSON.stringify(eMessageExtra)); // Return the replaced message content. return {}//如果要修改通知可以反回有数据通知 } onDestroy(): void { hilog.info(0x0000, TAG, 'RemoteNotificationExtAbility onDestroy.'); } }
              
              import { pushCommon, RemoteNotificationExtensionAbility } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { EPushInterface } from '@engagelab/push';

const TAG: string = 'ENGAGELAB-JLog-RemoteNotificationExtAbility'

export default class RemoteNotificationExtAbility extends RemoteNotificationExtensionAbility {
  async onReceiveMessage(remoteNotificationInfo: pushCommon.RemoteNotificationInfo): Promise<pushCommon.RemoteNotificationContent> {
    hilog.info(0x0000, TAG, 'onReceiveMessage, remoteNotificationInfo: %{public}s',
      JSON.stringify(remoteNotificationInfo));

    let eMessageExtra = await EPushInterface.receiveExtraDataMessage(this, remoteNotificationInfo);
    hilog.info(0x0000, TAG, 'onReceiveMessage eMessageExtra:' + JSON.stringify(eMessageExtra));
    // Return the replaced message content.
    return {}//如果要修改通知可以反回有数据通知
  }

  onDestroy(): void {
    hilog.info(0x0000, TAG, 'RemoteNotificationExtAbility onDestroy.');
  }
}

            
This code block in the floating window

参数说明

  • rNEAbility
    • 对应RemoteNotificationExtensionAbility
  • data
    • onReceiveMessage回调的参数数据,即通知扩展消息
  • return
    • 反回数据,EMessageExtra表示正确处理并反回了数据对象,undefined表示不是EngageLab的数据或异常出错

前台不展示功能处理函数(defaultMessageBackgroundData)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 如果使用前台不展示功能,请务必集成此函数,否则推送走鸿蒙通道下发,无法触发通知在前台不展示功能回调(onUnShowMessage),具体查看集成指南文档中:前台不展示功能进行操作

接口定义

/** * 「前台不展示功能」集成使用 * 「前台不展示功能」数据接收 * @param data 「前台不展示功能」消息数据 */ defaultMessageBackgroundData(data: pushCommon.PushPayload): Promise<boolean>
              
                  /**
     * 「前台不展示功能」集成使用
     * 「前台不展示功能」数据接收
     * @param data 「前台不展示功能」消息数据
     */
    defaultMessageBackgroundData(data: pushCommon.PushPayload): Promise<boolean>

            
This code block in the floating window

代码示例

import { UIAbility } from '@kit.AbilityKit'; import { EPushInterface } from '@engagelab/push'; import { pushCommon, pushService } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'ENGAGELAB-JLog-PushMessageAbility' export default class PushMessageAbility extends UIAbility { onCreate(): void { try { pushService.receiveMessage('DEFAULT', this, async (data: pushCommon.PushPayload) => { let jg = await EPushInterface.defaultMessageBackgroundData(data) if (jg) { //如果是true为已经处理 return } }); } catch (e) { hilog.info(0x0000, TAG, '%{public}s', 'DEFAULT fail:'+JSON.stringify(e)); } } }
              
              import { UIAbility } from '@kit.AbilityKit';
import { EPushInterface } from '@engagelab/push';
import { pushCommon, pushService } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const TAG: string = 'ENGAGELAB-JLog-PushMessageAbility'
export default class PushMessageAbility extends UIAbility {
  onCreate(): void {
    try {
      pushService.receiveMessage('DEFAULT', this, async (data: pushCommon.PushPayload) => {
        let jg = await EPushInterface.defaultMessageBackgroundData(data)
        if (jg) { //如果是true为已经处理
          return
        }
      });
    } catch (e) {
      hilog.info(0x0000, TAG, '%{public}s', 'DEFAULT fail:'+JSON.stringify(e));
    }
  }
}

            
This code block in the floating window

参数说明

  • data
    • receiveMessage中的参数固定为DEFAULT数据,即「前台不展示」消息数据
  • return
    • 反回数据,true表示正确处理了,false表示不是EngageLab的数据或异常出错

通过通知ID清除通知(clearNotification)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 通过通知ID清除指定通知
  • 只能清除已经显示过的通知

接口定义

/** * 通过通知ID清除通知 * @param id 通知ID */ clearNotification(id: number)
              
                  /**
     * 通过通知ID清除通知
     * @param id 通知ID
     */
    clearNotification(id: number)

            
This code block in the floating window

代码示例

EPushInterface.clearNotification(notificationId)
              
              EPushInterface.clearNotification(notificationId)

            
This code block in the floating window

参数说明

  • id 通知ID,用于指定要清除的通知

通过消息ID清除通知(clearNotificationByMsgId)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 通过消息ID清除指定通知
  • 只能清除已经显示过的通知

接口定义

/** * 通过消息ID清除通知 * @param msgId 消息ID */ clearNotificationByMsgId(msgId: string)
              
                  /**
     * 通过消息ID清除通知
     * @param msgId 消息ID
     */
    clearNotificationByMsgId(msgId: string)

            
This code block in the floating window

代码示例

EPushInterface.clearNotificationByMsgId("your_message_id")
              
              EPushInterface.clearNotificationByMsgId("your_message_id")

            
This code block in the floating window

参数说明

  • msgId 消息ID,用于指定要清除的通知

清除所有通知(clearNotificationAll)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 清除EngageLab展示的所有通知

接口定义

/** * 清除所有通知 */ clearNotificationAll()
              
                  /**
     * 清除所有通知
     */
    clearNotificationAll()

            
This code block in the floating window

代码示例

EPushInterface.clearNotificationAll()
              
              EPushInterface.clearNotificationAll()

            
This code block in the floating window

参数说明

消息状态上报 API

开始支持的版本:EPush HarmonyOS SDK v1.0.0

上报自定义消息展示(reportCustomDisplay)

功能说明

  • 请先init,否则调用无效

接口定义

/** * 上报自定义消息展示 * @param channel 数据来源通道 0:厂商通道 1:EngageLab通道 * @param msgId 消息ID */ reportCustomDisplay(channel: number, msgId: string)
              
                  /**
     * 上报自定义消息展示
     * @param channel 数据来源通道 0:厂商通道 1:EngageLab通道
     * @param msgId 消息ID
     */
    reportCustomDisplay(channel: number, msgId: string)

            
This code block in the floating window

代码示例

EPushInterface.reportCustomDisplay(eCustomMessage.channel, eCustomMessage.msgId as string)
              
              EPushInterface.reportCustomDisplay(eCustomMessage.channel, eCustomMessage.msgId as string)

            
This code block in the floating window

参数说明

  • channel: 数据来源通道
    • 0: 厂商通道
    • 1: EngageLab通道
  • msgId: 消息ID

上报自定义消息点击(reportCustomClick)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请先init,否则调用无效

接口定义

/** * 上报自定义消息点击 * @param channel 数据来源通道 0:厂商通道 1:EngageLab通道 * @param msgId 消息ID */ reportCustomClick(channel: number, msgId: string)
              
                  /**
     * 上报自定义消息点击
     * @param channel 数据来源通道 0:厂商通道 1:EngageLab通道
     * @param msgId 消息ID
     */
    reportCustomClick(channel: number, msgId: string)

            
This code block in the floating window

代码示例

EPushInterface.reportCustomClick(eCustomMessage.channel, eCustomMessage.msgId as string)
              
              EPushInterface.reportCustomClick(eCustomMessage.channel, eCustomMessage.msgId as string)

            
This code block in the floating window

参数说明

  • channel: 数据来源通道
    • 0: 厂商通道
    • 1: EngageLab通道
  • msgId: 消息ID

上报通知展示(reportNotificationDisplay)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请先init,否则调用无效

接口定义

/** * 上报通知展示 * @param channel 数据来源通道 0:厂商通道 1:EngageLab通道 * @param msgId 消息ID */ reportNotificationDisplay(channel: number, msgId: string)
              
                  /**
     * 上报通知展示
     * @param channel 数据来源通道 0:厂商通道 1:EngageLab通道
     * @param msgId 消息ID
     */
    reportNotificationDisplay(channel: number, msgId: string)

            
This code block in the floating window

代码示例

EPushInterface.reportNotificationDisplay(eMessage.channel, eMessage.msgId as string)
              
              EPushInterface.reportNotificationDisplay(eMessage.channel, eMessage.msgId as string)

            
This code block in the floating window

参数说明

  • channel: 数据来源通道
    • 0: 厂商通道
    • 1: EngageLab通道
  • msgId: 消息ID

上报通知点击(reportNotificationClick)

开始支持的版本:EPush HarmonyOS SDK v1.0.0

功能说明

  • 请先init,否则调用无效

接口定义

/** * 上报通知点击 * @param channel 数据来源通道 0:厂商通道 1:EngageLab通道 * @param msgId 消息ID */ reportNotificationClick(channel: number, msgId: string)
              
                  /**
     * 上报通知点击
     * @param channel 数据来源通道 0:厂商通道 1:EngageLab通道
     * @param msgId 消息ID
     */
    reportNotificationClick(channel: number, msgId: string)

            
This code block in the floating window

代码示例

EPushInterface.reportNotificationClick(eMessage.channel, eMessage.msgId as string)
              
              EPushInterface.reportNotificationClick(eMessage.channel, eMessage.msgId as string)

            
This code block in the floating window

参数说明

  • channel: 数据来源通道
    • 0: 厂商通道
    • 1: EngageLab通道
  • msgId: 消息ID
icon
Contact Sales