HarmonyOS SDK API

Last updated:2025-08-04
Expand all
HarmonyOS SDK API

Set debug mode API(setDebug)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please AbilityStage(#onCreate) called inside
  • please init Called before
  • Optional interface

Interface definition

/** * 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 is shown in the floating window

code example

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

        
This code block is shown in the floating window

Parameter description

  • debug for true will print debug level logs,false will only print warning Logs above level

ConfigurationJiguang Appkey(setAppKey)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please AbilityStage(#onCreate) called inside
  • please init Called before
  • The interface that must be called

Interface definition

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

        
This code block is shown in the floating window

code example

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

        
This code block is shown in the floating window

Parameter description

  • appKey Need to start fromJiguangConsole acquisition.

Configure download channel (setChannel)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

Dynamic configuration channel(Package download channel)

  • channel Specify the download channel of the application package. To facilitate statistics by channel, the specific value is defined by you, such as Huawei App Market, etc.
  • JPush HarmonyOS SDK v1.1.0 Supported by the above versions.
  • please AbilityStage(#onCreate) called inside
  • please init Called before
  • The interface that must be called

Interface definition

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

        
This code block is shown in the floating window

code example

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

        
This code block is shown in the floating window

Parameter description

  • channel User business customization.

Configure the number of custom information cache items (setCustomMessageMaxCacheCount)

Versions supported starting from:JPush HarmonyOS SDK v1.2.0

Function description

This interface is used to pushJiguangCustom messages (not applicable to notification messages), for some APP Special business scenarios; such as: when your server sends100When custom messages are sent to a user, if you only want to process and save the latest 10 messages based on business characteristics or your own business processing performance, you can use this interface.

  • please AbilityStage(#onCreate) called inside
  • please init Called before

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.setCustomMessageMaxCacheCount(2)
          JPushInterface.setCustomMessageMaxCacheCount(2)

        
This code block is shown in the floating window

Parameter description

  • maxCacheCount Number of cached items

Control notification permission application method (setUserRequestNotificationPermission)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Function description

Set whether the developer calls the notification to apply for permission. When set totruehour,JiguangSDKNotification permissions will not be actively applied for. Developers need to manually apply for notification permissions in their own code; when set tofalsehour,JiguangSDKNotification permission will be automatically applied for during initialization.

  • please AbilityStage(#onCreate) called inside
  • please init Called before
  • Optional interface

Interface definition

/** * 设置是否由用户自己调用通知申请权限 * @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 is shown in the floating window

code example

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

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

        
This code block is shown in the floating window

Parameter description

  • enable for true Indicates setting the developer to apply for notification permission by himself, which is false expressJiguangSDKApply for notification permission (default)

Set whether to actively disconnect long connections when entering the background (setBackgroundEnable)

Versions supported starting from:JPush HarmonyOS SDK v1.3.5

Function description

Set whether to actively disconnect from the server when the application enters the background TCP Long connection. set to false(default), it will automatically disconnect when entering the background; set to true When entering the background, it will not automatically disconnect.

  • please AbilityStage(#onCreate) called inside
  • please init Called before
  • Optional interface

Interface definition

/** * 设置应用进入后台时是否主动断开与服务器的 TCP 长连接。 * 设为 false(默认)时,进入后台会主动断开;设为 true 时,进入后台不主动断开。 * * @param enable true 表示进入后台不主动断开,false 表示进入后台时主动断开 */ setBackgroundEnable(enable: boolean)
              /**
     * 设置应用进入后台时是否主动断开与服务器的 TCP 长连接。
     * 设为 false(默认)时,进入后台会主动断开;设为 true 时,进入后台不主动断开。
     *
     * @param enable true 表示进入后台不主动断开,false 表示进入后台时主动断开
     */
    setBackgroundEnable(enable: boolean)

        
This code block is shown in the floating window

code example

// 进入后台时主动断开长连接(默认) JPushInterface.setBackgroundEnable(false) // 进入后台不主动断开 JPushInterface.setBackgroundEnable(true)
          // 进入后台时主动断开长连接(默认)
JPushInterface.setBackgroundEnable(false)

// 进入后台不主动断开
JPushInterface.setBackgroundEnable(true)

        
This code block is shown in the floating window

Parameter description

  • enable for true It means entering the background and not automatically disconnecting. false Indicates active disconnection when entering the background (default)

Enable push service function API(init)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

JPushservice, calling this API After that, turn onJPush Push service will start collecting and reportingSDKUser personal information necessary for business functions.

  • Called at startup

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.init(this.context)
          JPushInterface.init(this.context)

        
This code block is shown in the floating window

Parameter description

  • context existAbilityStageIntermediate pass common.AbilityStageContext,existUIAbilityIntermediate pass common.UIAbilityContext

Interface usage instructions

  • If the developer actively calls init method will be enabledJPushPush service.
  • consider APP For online compliance, developers must beAPPThe user agrees to the privacy policy and the developer identifies asAppAfter the user starts to provide push services, the user can then call the enable push service function interface to useJiguangServe.
  • about APP Privacy policy suggestions and instructions, please refer to How to draft a compliant privacy policy

get RegistrationID(getRegistrationId)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please firstinit, otherwise the call is invalid

Interface definition

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

        
This code block is shown in the floating window

code example

let rid = JPushInterface.getRegistrationId()
          let rid = JPushInterface.getRegistrationId()

        
This code block is shown in the floating window

Parameter description

  • none

Set callback interface (setCallBackMsg)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

This interface is used to receivesdkData. For example: callbacks for registration results, login results, notification click results, label alias operation results, etc. The receiving class needs to be implementedCallBackMsginterface,CallBackMsgSee code examples for functions.

  • please AbilityStage(#onCreate) called inside
  • please init Called before
  • The interface that must be called

Interface definition

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

        
This code block is shown in the floating window

code example

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 jTagMessage * export class JTagMessage { * sequence?: number //对应操作id,全局不要重复 * code?: number //0成功,JTagMessage.CODE_TIME_OUT超时 * op?: string * tags?: string[] //对应数据 * curr?: number //数据当前页数,页数从1开始 * total?: number //数据总页数 * msg?: string * validated?:boolean //checkTagBindState 查询tag是否存在 * } */ onTagOperatorResult(jTagMessage: JTagMessage): void { hilog.info(0x0000, 'testTag', '%{public}s', 'onTagOperatorResult JTagMessage:' + JSON.stringify(jTagMessage)); this.context.eventHub.emit('jPush_event', "onTagOperatorResult:" + JSON.stringify(jTagMessage)); } /** * 操作 Alias 接口回调 * @param jAliasMessage * export class JAliasMessage { * sequence?: number //对应操作id,全局不要重复 * code?: number //0成功,JAliasMessage.CODE_TIME_OUT超时 * op?: string * alias?: string //对应数据 * curr?: number * total?: number * msg?: string * } */ onAliasOperatorResult(jAliasMessage: JAliasMessage): void { hilog.info(0x0000, 'testTag', '%{public}s', 'onAliasOperatorResult jAliasMessage:' + JSON.stringify(jAliasMessage)); this.context.eventHub.emit('jPush_event', "onAliasOperatorResult:" + JSON.stringify(jAliasMessage)); } /** * 通知点击事件回调 * @param jMessage * * export class JMessage { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * channel?: number //数据来源通道 0:厂商通道 1:极光通道(开始支持的版本:JPush HarmonyOS SDK v1.3.0) * } */ onClickMessage(jMessage: JMessage) { hilog.info(0x0000, 'testTag', '%{public}s', 'onClickMessage jMessage:' + JSON.stringify(jMessage)); this.context.eventHub.emit('jPush_event', "onClickMessage:" + JSON.stringify(jMessage)); } /** * 通知到达事件回调(仅通过极光通道下发通知会触发此函数,通过鸿蒙系统通道下发通知由设备系统处理,暂不支持回调) * 开始支持的版本:JPush HarmonyOS SDK v1.3.0 * @param jMessage * * export class JMessage { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * channel?: number //数据来源通道 0:厂商通道 1:极光通道(实际情况,此处获取到的值只有可能是1) * } */ onArrivedMessage(jMessage: JMessage) { hilog.info(0x0000, 'testTag', '%{public}s', 'onArrivedMessage jMessage:' + JSON.stringify(jMessage)); this.context.eventHub.emit('jPush_event', "onArrivedMessage:" + JSON.stringify(jMessage)); } /** * 通知在前台不展示功能生效时触发的事件回调 * 开始支持的版本:JPush HarmonyOS SDK v1.3.0 * @param jMessage * * export class JMessage { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * channel?: number //数据来源通道 0:厂商通道 1:极光通道 * } */ onUnShowMessage(jMessage: JMessage) { hilog.info(0x0000, 'testTag', '%{public}s', 'onUnShowMessage jMessage:' + JSON.stringify(jMessage)); this.context.eventHub.emit('jPush_event', "onUnShowMessage:" + JSON.stringify(jMessage)); } /** * 自定义信息回调 * 回调一:冷启动调用sdk初始化后回调之前还没有回调的信息 * 回调二:app存活时会直接回调信息 * 想要触发自定义信息走厂商通道下发时回调,请关注接口「customMessageBackgroundData」说明,或查看集成指南的「配置自定义信息」说明。 * @param jCustomMessage * * export class JCustomMessage { * msgId?: string //通知id * title?: string //通知标题 * content?: string //通知内容 * contentType?: string //通知内容类型 * extras?: Record<string, Object> //通知自定义键值对 * ttl?: number //后台下发的信息过期时间,单位秒 * stime?: number //后台下发时间,毫秒 * channel?: number //数据来源通道 0:厂商通道 1:极光通道(开始支持的版本:JPush HarmonyOS SDK v1.3.0) * } */ onCustomMessage(jCustomMessage: JCustomMessage) { hilog.info(0x0000, TAG, '%{public}s', 'onCustomMessage jCustomMessage:' + JSON.stringify(jCustomMessage)); this.context.eventHub.emit('jPush_event', "onCustomMessage:" + JSON.stringify(jCustomMessage)); } /** * 通知扩展消息回调 * 想要触发通知扩展消息走厂商通道下发时回调,请关注接口「extraMessageBackgroundData」、「receiveExtraDataMessage」说明,或查看集成指南的「配置通知扩展消息」说明。 * * @param jMessageExtra * * export class JMessageExtra { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * extraData?: string//通知扩展消息的自定义数据 * } */ onJMessageExtra(jme: JMessageExtra) { hilog.info(0x0000, TAG, '%{public}s', 'onJMessageExtra jme:' + JSON.stringify(jme)); this.context.eventHub.emit('jPush_event', "onJMessageExtra:" + JSON.stringify(jme)); } /** * VoIP呼叫消息回调 * 想要触发VoIP呼叫消息走厂商通道下发时回调,请关注接口「voIPMessageBackgroundData」说明,或查看集成指南的「配置推送VoIP呼叫消息」说明。 * * export class JMessageVoIP { * msgId?: string //通知id * extraData?: string //VoIP自定义数据 } * @param jmVoIP */ onJMessageVoIP(jmVoIP: JMessageVoIP) { hilog.info(0x0000, TAG, '%{public}s', 'JMessageVoIP jmVoIP:' + JSON.stringify(jmVoIP)); this.context.eventHub.emit('jPush_event', "JMessageVoIP:" + JSON.stringify(jmVoIP)); } /** * 手机号操作结果回调 * @param jMobileNumberMessage * * export class JMobileNumberMessage { * sequence?: number //对应操作id,全局不要重复 * code?: number //0成功 * } */ onMobileNumberOperatorResult(jMobileNumberMessage: JMobileNumberMessage) { hilog.info(0x0000, 'testTag', '%{public}s', 'onMobileNumberOperatorResult jMobileNumberMessage:' + JSON.stringify(jMobileNumberMessage)); this.context.eventHub.emit('jPush_event', "onMobileNumberOperatorResult:" + JSON.stringify(jMobileNumberMessage)); } /** * export class JCmdMessage { * public static CMD_PUSH_STOP = 2007 //通知停止 设置回调 * public static CMD_PUSH_RESUME = 2006 // 通知恢复 设置回调 * cmd?: number //操作类型 * errorCode?: number //状态码 * msg?: string //内容 * extra?: Record<string, Object> * } * @param cmdMessage */ onCommandResult(cmdMessage: JCmdMessage) { hilog.info(0x0000, TAG, '%{public}s', 'onCommandResult cmdMessage:' + JSON.stringify(cmdMessage)); this.context.eventHub.emit('jPush_event', "onCommandResult:" + JSON.stringify(cmdMessage)); } } JPushInterface.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 jTagMessage
   * export class JTagMessage {
   * sequence?: number //对应操作id,全局不要重复
   * code?: number //0成功,JTagMessage.CODE_TIME_OUT超时
   * op?: string
   * tags?: string[] //对应数据
   * curr?: number //数据当前页数,页数从1开始
   * total?: number //数据总页数
   * msg?: string
   * validated?:boolean //checkTagBindState 查询tag是否存在
   * }
   */
  onTagOperatorResult(jTagMessage: JTagMessage): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onTagOperatorResult JTagMessage:' + JSON.stringify(jTagMessage));
    this.context.eventHub.emit('jPush_event', "onTagOperatorResult:" + JSON.stringify(jTagMessage));
  }

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

  /**
   * 通知点击事件回调
   * @param jMessage
   *
   * export class JMessage {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * channel?: number //数据来源通道 0:厂商通道 1:极光通道(开始支持的版本:JPush HarmonyOS SDK v1.3.0)
   * }
   */
  onClickMessage(jMessage: JMessage) {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onClickMessage jMessage:' + JSON.stringify(jMessage));
    this.context.eventHub.emit('jPush_event', "onClickMessage:" + JSON.stringify(jMessage));
  }
  
  /**
   * 通知到达事件回调(仅通过极光通道下发通知会触发此函数,通过鸿蒙系统通道下发通知由设备系统处理,暂不支持回调)
   * 开始支持的版本:JPush HarmonyOS SDK v1.3.0
   * @param jMessage
   *
   * export class JMessage {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * channel?: number //数据来源通道 0:厂商通道 1:极光通道(实际情况,此处获取到的值只有可能是1)
   * }
   */
  onArrivedMessage(jMessage: JMessage) {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onArrivedMessage jMessage:' + JSON.stringify(jMessage));
    this.context.eventHub.emit('jPush_event', "onArrivedMessage:" + JSON.stringify(jMessage));
  }
  
  /**
   * 通知在前台不展示功能生效时触发的事件回调
   * 开始支持的版本:JPush HarmonyOS SDK v1.3.0
   * @param jMessage
   *
   * export class JMessage {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * channel?: number //数据来源通道 0:厂商通道 1:极光通道
   * }
   */
  onUnShowMessage(jMessage: JMessage) {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onUnShowMessage jMessage:' + JSON.stringify(jMessage));
    this.context.eventHub.emit('jPush_event', "onUnShowMessage:" + JSON.stringify(jMessage));
  }
  
   /**
   * 自定义信息回调
   *  回调一:冷启动调用sdk初始化后回调之前还没有回调的信息
   *  回调二:app存活时会直接回调信息
   *  想要触发自定义信息走厂商通道下发时回调,请关注接口「customMessageBackgroundData」说明,或查看集成指南的「配置自定义信息」说明。
   * @param jCustomMessage
   *
   * export class JCustomMessage {
   *  msgId?: string //通知id
   *  title?: string //通知标题
   *  content?: string //通知内容
   *  contentType?: string //通知内容类型
   *  extras?: Record<string, Object> //通知自定义键值对
   *  ttl?: number //后台下发的信息过期时间,单位秒
   *  stime?: number //后台下发时间,毫秒
   *  channel?: number //数据来源通道 0:厂商通道 1:极光通道(开始支持的版本:JPush HarmonyOS SDK v1.3.0)
   * }
   */
  onCustomMessage(jCustomMessage: JCustomMessage) {
    hilog.info(0x0000, TAG, '%{public}s', 'onCustomMessage jCustomMessage:' + JSON.stringify(jCustomMessage));
    this.context.eventHub.emit('jPush_event', "onCustomMessage:" + JSON.stringify(jCustomMessage));
  }
  
  /**
   * 通知扩展消息回调
   * 想要触发通知扩展消息走厂商通道下发时回调,请关注接口「extraMessageBackgroundData」、「receiveExtraDataMessage」说明,或查看集成指南的「配置通知扩展消息」说明。
   * 
   * @param jMessageExtra
   *
   * export class JMessageExtra {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * extraData?: string//通知扩展消息的自定义数据
   * }
   */
  onJMessageExtra(jme: JMessageExtra) {
    hilog.info(0x0000, TAG, '%{public}s', 'onJMessageExtra jme:' + JSON.stringify(jme));
    this.context.eventHub.emit('jPush_event', "onJMessageExtra:" + JSON.stringify(jme));
  }
  
  /**
   * VoIP呼叫消息回调
   * 想要触发VoIP呼叫消息走厂商通道下发时回调,请关注接口「voIPMessageBackgroundData」说明,或查看集成指南的「配置推送VoIP呼叫消息」说明。
   * 
   * export class JMessageVoIP {
   * msgId?: string //通知id
   * extraData?: string //VoIP自定义数据
   }
   * @param jmVoIP
   */
  onJMessageVoIP(jmVoIP: JMessageVoIP) {
    hilog.info(0x0000, TAG, '%{public}s', 'JMessageVoIP jmVoIP:' + JSON.stringify(jmVoIP));
    this.context.eventHub.emit('jPush_event', "JMessageVoIP:" + JSON.stringify(jmVoIP));
  }
  
  /**
   * 手机号操作结果回调
   * @param jMobileNumberMessage
   *
   * export class JMobileNumberMessage {
   * sequence?: number //对应操作id,全局不要重复
   * code?: number //0成功
   * }
   */
  onMobileNumberOperatorResult(jMobileNumberMessage: JMobileNumberMessage) {
    hilog.info(0x0000, 'testTag', '%{public}s', 'onMobileNumberOperatorResult jMobileNumberMessage:' + JSON.stringify(jMobileNumberMessage));
    this.context.eventHub.emit('jPush_event', "onMobileNumberOperatorResult:" + JSON.stringify(jMobileNumberMessage));
  }
  
   /**
   * export class JCmdMessage {
   * public static CMD_PUSH_STOP = 2007 //通知停止 设置回调
   * public static CMD_PUSH_RESUME = 2006 //    通知恢复 设置回调
   * cmd?: number //操作类型
   * errorCode?: number //状态码
   * msg?: string //内容
   * extra?: Record<string, Object>
   * }
   * @param cmdMessage
   */
  onCommandResult(cmdMessage: JCmdMessage) {
    hilog.info(0x0000, TAG, '%{public}s', 'onCommandResult cmdMessage:' + JSON.stringify(cmdMessage));
    this.context.eventHub.emit('jPush_event', "onCommandResult:" + JSON.stringify(cmdMessage));
  }
}


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

        
This code block is shown in the floating window

Parameter description

  • callBackMsg: take oversdkData callback class, needs to be inheritedCallBackMsginterface

Callback method details

Registration result callback (onRegister)

Registration result callback

Interface definition
/** * 注册结果回调 * * @param registrationId rid */ onRegister(registrationId: string)
              /**
     * 注册结果回调
     *
     * @param registrationId  rid   
     */        
    onRegister(registrationId: string)

        
This code block is shown in the floating window

Long connection status callback (isConnected)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

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

        
This code block is shown in the floating window

Notification click event callback (onClickMessage)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

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

        
This code block is shown in the floating window

Notification arrival event callback (onArrivedMessage)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0 Description: Pass onlyJiguangNotifications sent through the channel will trigger this function. Notifications sent through the Hongmeng system channel are processed by the device system. Callbacks are not supported for the time being.

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

        
This code block is shown in the floating window

Notifications do not display function callbacks in the foreground (onUnShowMessage)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

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

        
This code block is shown in the floating window

Interaction event callback (onCommandResult)

Interface definition
/** * 交互事件回调 * @param cmdMessage * export class JCmdMessage { * public static CMD_PUSH_STOP = 2007 //通知停止 设置回调 * public static CMD_PUSH_RESUME = 2006 // 通知恢复 设置回调 * public static readonly CMD_TOKEN = 10000 // token 注册回调(开始支持的版本:JPush HarmonyOS SDK v1.3.0) * * cmd?: number //操作事件,2007通知停止,2006恢复通知 * errorCode?: number //0表示成功,其他为错误 * msg?: string //内容信息 * extra?: Record<string, Object> * } */ onCommandResult(cmdMessage: JCmdMessage);
            /**
   * 交互事件回调
   * @param cmdMessage
   * export class JCmdMessage {
   * public static CMD_PUSH_STOP = 2007 //通知停止 设置回调
   * public static CMD_PUSH_RESUME = 2006 //    通知恢复 设置回调
   * public static readonly CMD_TOKEN = 10000 //    token 注册回调(开始支持的版本:JPush HarmonyOS SDK v1.3.0)
   *
   * cmd?: number  //操作事件,2007通知停止,2006恢复通知
   * errorCode?: number //0表示成功,其他为错误
   * msg?: string //内容信息
   * extra?: Record<string, Object>
   * }
   */
  onCommandResult(cmdMessage: JCmdMessage);

        
This code block is shown in the floating window
cmd errorCode msg DESCRIPTION
0 fail code Failure message Registration failed
2006 0 success onResume Set callback
2007 0 success onStop Set callback
10000 0/1 success/fail gettoken, 0: success, 1: failure

Background custom information callback (onCustomMessage)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

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

        
This code block is shown in the floating window

Notification extension message callback (onJMessageExtra)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Interface definition
/** * 通知扩展消息回调 * @param jMessageExtra * * export class JMessageExtra { * msgId?: string //通知id * title?: string //通知标题 * content?: string//通知内容 * extras?: Record<string, Object>//自定义数据 * extraData?: string//通知扩展消息的自定义数据 * } */ onJMessageExtra(jme: JMessageExtra);
            /**
   * 通知扩展消息回调
   * @param jMessageExtra
   *
   * export class JMessageExtra {
   * msgId?: string //通知id
   * title?: string //通知标题
   * content?: string//通知内容
   * extras?: Record<string, Object>//自定义数据
   * extraData?: string//通知扩展消息的自定义数据
   * }
   */
  onJMessageExtra(jme: JMessageExtra);

        
This code block is shown in the floating window

VoIPcall message callback(onJMessageVoIP)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Interface definition
/** * VoIP呼叫消息回调 * export class JMessageVoIP { * msgId?: string //通知id * extraData?: string //VoIP自定义数据 } * @param jmVoIP */ onJMessageVoIP(jmVoIP: JMessageVoIP);
             /**
   * VoIP呼叫消息回调
   * export class JMessageVoIP {
   * msgId?: string //通知id
   * extraData?: string //VoIP自定义数据
   }
   * @param jmVoIP
   */
  onJMessageVoIP(jmVoIP: JMessageVoIP);

        
This code block is shown in the floating window

operate tag interface callback (onTagOperatorResult)

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

        
This code block is shown in the floating window

operate Alias interface callback (onAliasOperatorResult)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

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

        
This code block is shown in the floating window

Operation mobile phone number interface callback (onMobileNumberOperatorResult)

Versions supported starting from:JPush HarmonyOS SDK v1.1.1

Interface definition
/** * 操作手机号接口回调 export class JMobileNumberMessage { sequence?: number //对应操作id,全局不要重复 code?: number //0成功 } * * @param jMobileNumberMessage */ onMobileNumberOperatorResult(jMobileNumberMessage: JMobileNumberMessage)
            /**
   * 操作手机号接口回调
     export class JMobileNumberMessage {
      sequence?: number //对应操作id,全局不要重复
      code?: number //0成功
     }
   *
   * @param jMobileNumberMessage
   */
  onMobileNumberOperatorResult(jMobileNumberMessage: JMobileNumberMessage)

        
This code block is shown in the floating window

Notification jump data reception (setClickWant)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

In order to receive the corresponding data for the callback after the notification is clicked On the notification jump pageUIAbilityofonCreate、onNewWantCall in: pass inwant Then it will pass the callback interface set aboveCallBackMsgin classonClickMessageMethod callback

  • please firstsetAppKey, otherwise the call is invalid

Interface definition

/** * 在通知跳转页面UIAbility的onCreate、onNewWant中调用:传入want,通过上面的onClickMessage接口回调自定义数据 * * @param want */ setClickWant(want: Want): Promise<JMessage | undefined>
             /**
   * 在通知跳转页面UIAbility的onCreate、onNewWant中调用:传入want,通过上面的onClickMessage接口回调自定义数据
   *
   * @param want
   */
    setClickWant(want: Want): Promise<JMessage | undefined>

        
This code block is shown in the floating window

code example

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:JMessage|undefined = await JPushInterface.setClickWant(want); 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:JMessage|undefined = await JPushInterface.setClickWant(want);
    hilog.info(0x0000, TAG, '%{public}s', 'setClickWant: '+JSON.stringify(j));
}

        
This code block is shown in the floating window

Parameter description

  • want:forUIAbilityinwant

  • return

    • Return data,JMessageIndicates that the data object was correctly processed and returned,undefinedIndicates no data or is notJiguangData or exception error

stop notification(stopPush)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Function description

  • please firstinit, otherwise the call is invalid
  • The result isonCommandResult(cmdMessage: JCmdMessage) callback

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.stopPush()
          JPushInterface.stopPush()

        
This code block is shown in the floating window

Parameter description

  • none

resume notification (resumePush)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Function description

  • please firstinit, otherwise the call is invalid
  • The result isonCommandResult(cmdMessage: JCmdMessage) callback

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.resumePush()
          JPushInterface.resumePush()

        
This code block is shown in the floating window

Parameter description

  • none

Notification status query (isPushStopped)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Function description

  • please firstinit, otherwise the call is invalid

Interface definition

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

        
This code block is shown in the floating window

code example

let isPushStopped = JPushInterface.isPushStopped()
          let isPushStopped = JPushInterface.isPushStopped()

        
This code block is shown in the floating window

Parameter description

  • Return value:truestop,falsenormal,undefinedAbnormal situations such as no initialization

Tags and aliases-api

Add new tag (addTags)

Function description

  • please firstinit, otherwise the call is invalid
  • If there is no problem with the environment,onTagOperatorResultWill call back the result

Interface definition

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

        
This code block is shown in the floating window

code example

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

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation.
  • tags
    • Each call adds at least one new tag。
    • Valid tags consist of: letters (case sensitive), numbers, underscores, Chinese characters, special characters @!#$&*+=.|.
    • Limit: each tag The name length is limited to 40 bytes and supports up to 1000 indivual tag, and the total length of a single operation shall not exceed 5000 byte. (To judge the length, you need to use UTF-8 coding) A single device supports at most settings 1000 indivual tag。App overall situation tag Unlimited quantity.

delete tag(deleteTags)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please firstinit, otherwise the call is invalid
  • If there is no problem with the environment,onTagOperatorResultWill call back the result

Interface definition

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

        
This code block is shown in the floating window

code example

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

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation.
  • tags
    • Delete at least one per call tag。
    • Valid tags consist of: letters (case sensitive), numbers, underscores, Chinese characters, special characters @!#$&*+=.|.
    • Limit: each tag The name length is limited to 40 bytes and supports up to 1000 indivual tag, and the total length of a single operation shall not exceed 5000 byte. (To judge the length, you need to use UTF-8 coding) A single device supports at most settings 1000 indivual tag。App overall situation tag Unlimited quantity.

set label(setTags)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please firstinit, otherwise the call is invalid
  • If there is no problem with the environment,onTagOperatorResultWill call back the result

Interface definition

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

        
This code block is shown in the floating window

code example

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

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation.
  • tags
    • Each call adds at least one new tag。
    • Valid tags consist of: letters (case sensitive), numbers, underscores, Chinese characters, special characters @!#$&*+=.|.
    • Limit: each tag The name length is limited to 40 bytes and supports up to 1000 indivual tag, and the total length of a single operation shall not exceed 5000 byte. (To judge the length, you need to use UTF-8 coding) A single device supports at most settings 1000 indivual tag。App overall situation tag Unlimited quantity.

Query the binding status of the specified tag (checkTagBindState)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please firstinit, otherwise the call is invalid
  • If there is no problem with the environment,onTagOperatorResultWill call back the result

Interface definition

/** * 查询指定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 is shown in the floating window

code example

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

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation.
  • tags
    • queried tag

clear all tags (cleanTags)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please firstinit, otherwise the call is invalid
  • If there is no problem with the environment,onTagOperatorResultWill call back the result

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.cleanTags(this.sequence++)
          JPushInterface.cleanTags(this.sequence++)

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation.

Query all tags (getTags)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please firstinit, otherwise the call is invalid
  • If there is no problem with the environment,onTagOperatorResultWill call back the result

Interface definition

/** * 查询所有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 is shown in the floating window

code example

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

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation.

set alias (setAlias)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please firstinit, otherwise the call is invalid
  • If there is no problem with the environment,onAliasOperatorResultWill call back the result

Interface definition

/** * 设置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 is shown in the floating window

code example

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

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation. It is recommended to use a different numerical sequence number each time.
  • alias
    • Each call sets a valid alias, overwriting the previous setting.
    • Valid aliases consist of: letters (case sensitive), numbers, underscores, Chinese characters, special characters @!#$&*+=.|.
    • limit:alias Name length is limited to 40 bytes. (To judge the length, you need to use UTF-8 coding)

Query alias (getAlias)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please firstinit, otherwise the call is invalid
  • If there is no problem with the environment,onAliasOperatorResultWill call back the result

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.getAlias(this.sequence++)
          JPushInterface.getAlias(this.sequence++)

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation. It is recommended to use a different numerical sequence number each time.

Delete alias (deleteAlias)

Versions supported starting from:JPush HarmonyOS SDK v1.0.0

Function description

  • please firstinit, otherwise the call is invalid
  • If there is no problem with the environment,onAliasOperatorResultWill call back the result

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.deleteAlias(this.sequence++)
          JPushInterface.deleteAlias(this.sequence++)

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation. It is recommended to use a different numerical sequence number each time.

Set mobile phone number (setMobileNumber)

Versions supported starting from:JPush HarmonyOS SDK v1.1.1

Function description

  • please firstinit, otherwise the call is invalid

Interface definition

/** * 设置手机号 * * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性,推荐每次都用不同的数字序号。 * @param mobileNumber 手机号 */ setMobileNumber(sequence: number, mobileNumber: string)
              /**
     * 设置手机号
     *
     * @param sequence 用户自定义的操作序列号,同操作结果一起返回,用来标识一次操作的唯一性,推荐每次都用不同的数字序号。
     * @param mobileNumber 手机号
     */
    setMobileNumber(sequence: number, mobileNumber: string)

        
This code block is shown in the floating window

code example

JPushInterface.setMobileNumber(this.sequence++,"155xxxxxxxx)
            JPushInterface.setMobileNumber(this.sequence++,"155xxxxxxxx)

        
This code block is shown in the floating window

Parameter description

  • sequence
    • The user-defined operation sequence number is returned together with the operation result and is used to identify the uniqueness of an operation. It is recommended to use a different numerical sequence number each time.
  • mobileNumber
    • Phone number

Set the corner mark (setBadgeNumber)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Function description

  • please firstinit, otherwise the call is invalid

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.setBadgeNumber(0)
            JPushInterface.setBadgeNumber(0)

        
This code block is shown in the floating window

Parameter description

  • badgeNumber
    • index value

Custom message reception (customMessageBackgroundData)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Function description

  • This function only handles the scenario where custom messages are delivered through Hongmeng. If your business uses custom messages, please be sure to follow the integration guide document:Configure custom informationperform operations

Interface definition

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

        
This code block is shown in the floating window

code example

import { UIAbility } from '@kit.AbilityKit'; import { JPushInterface } from '@jg/push'; import { pushCommon, pushService } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'JPUSH-JLog-PushMessageAbility' export default class PushMessageAbility extends UIAbility { onCreate(): void { try { // receiveMessage中的参数固定为BACKGROUND-------后台自定义信息接收 pushService.receiveMessage('BACKGROUND', this, async (data: pushCommon.PushPayload) => { let jg = await JPushInterface.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 { JPushInterface } from '@jg/push';
import { pushCommon, pushService } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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

        
This code block is shown in the floating window

Parameter description

  • data
    • receiveMessageThe parameters in are fixed toBACKGROUNDData, that is, background data
  • return
    • Return data,trueIt means it was handled correctly,falsemeans noJiguangData or exception error

VoIPCall message reception (voIPMessageBackgroundData)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Function description

  • This function only handlesVoIPIn the scenario where the call message is delivered by Hongmeng, if the business usesVoIPTo call messages, be sure to follow the integration guide documentation:Configuration pushVoIPcall messageperform operations

Interface definition

/** * 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 is shown in the floating window

code example

import { UIAbility } from '@kit.AbilityKit'; import { JPushInterface } from '@jg/push'; import { pushCommon, pushService } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'JPUSH-JLog-PushMessageAbility' export default class PushMessageAbility extends UIAbility { onCreate(): void { try { pushService.receiveMessage('VoIP', this, async (data) => { let jg = await JPushInterface.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 { JPushInterface } from '@jg/push';
import { pushCommon, pushService } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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


}

        
This code block is shown in the floating window

Parameter description

  • data
    • receiveMessageThe parameters in are fixed toVoIPData, instantVoIPcall message
  • return
    • Return data,trueIt means it was handled correctly,falsemeans noJiguangData or exception error

Notification extended message reception--when the process is alive (extraMessageBackgroundData)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Function description

  • This function only handles the scenario where notification extension messages are delivered through Hongmeng. If the business uses notification extension messages, please be sure to follow the integration guide document:Configure notification extension messagesperform operations

Interface definition

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

        
This code block is shown in the floating window

code example

import { UIAbility } from '@kit.AbilityKit'; import { JPushInterface } from '@jg/push'; import { pushCommon, pushService } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'JPUSH-JLog-PushMessageAbility' export default class PushMessageAbility extends UIAbility { onCreate(): void { try { // receiveMessage中的参数固定为IM-------拓展通知接收 pushService.receiveMessage('IM', this, async (data) => { let jg = await JPushInterface.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 { JPushInterface } from '@jg/push';
import { pushCommon, pushService } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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

        
This code block is shown in the floating window

Parameter description

  • data
    • receiveMessageThe parameters in are fixed to IM data, that is, notification extended message
  • return
    • Return data,trueIt means it was handled correctly,falsemeans noJiguangData or exception error

Notification extended message reception--process does not exist (receiveExtraDataMessage)

Versions supported starting from:JPush HarmonyOS SDK v1.1.0

Function description

  • This function only handles the scenario where notification extension messages are delivered through Hongmeng. If the business uses notification extension messages, please be sure to follow the integration guide document:Configure notification extension messagesperform operations

Interface definition

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

        
This code block is shown in the floating window

code example

import { pushCommon, RemoteNotificationExtensionAbility } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { JPushInterface } from '@jg/push'; const TAG: string = 'JPUSH-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 jMessageExtra = await JPushInterface.receiveExtraDataMessage(this, remoteNotificationInfo); hilog.info(0x0000, TAG, 'onReceiveMessage jMessageExtra:' + JSON.stringify(jMessageExtra)); // 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 { JPushInterface } from '@jg/push';

const TAG: string = 'JPUSH-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 jMessageExtra = await JPushInterface.receiveExtraDataMessage(this, remoteNotificationInfo);
    hilog.info(0x0000, TAG, 'onReceiveMessage jMessageExtra:' + JSON.stringify(jMessageExtra));
    // Return the replaced message content.
    return {}//如果要修改通知可以反回有数据通知
  }

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

        
This code block is shown in the floating window

Parameter description

  • rNEAbility
    • correspondRemoteNotificationExtensionAbility
  • data
    • onReceiveMessageThe parameter data of the callback, that is, the notification extension message
  • return
    • Return data,JMessageExtraIndicates that the data object was correctly processed and returned,undefinedmeans noJiguangData or exception error

The function processing function is not displayed in the frontend (defaultMessageBackgroundData)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Function description

  • If you use the function of not displaying in the foreground, be sure to integrate this function, otherwise the push will be sent through the Hongmeng channel and the notification of the function callback of not displaying in the foreground will not be triggered (onUnShowMessage), see the integration guide document for details:The front desk does not display functionsperform operations

Interface definition

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

        
This code block is shown in the floating window

code example

import { UIAbility } from '@kit.AbilityKit'; import { JPushInterface } from '@jg/push'; import { pushCommon, pushService } from '@kit.PushKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'JPUSH-JLog-PushMessageAbility' export default class PushMessageAbility extends UIAbility { onCreate(): void { try { pushService.receiveMessage('DEFAULT', this, async (data: pushCommon.PushPayload) => { let jg = await JPushInterface.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 { JPushInterface } from '@jg/push';
import { pushCommon, pushService } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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

        
This code block is shown in the floating window

Parameter description

  • data
    • receiveMessageThe parameters in are fixed toDEFAULTData, that is, "not displayed in the front desk" message data
  • return
    • Return data,trueIt means it was handled correctly,falsemeans noJiguangData or exception error

Clear notification by message ID (clearNotificationByMsgId)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Function description

  • Clear specified notification by message ID
  • Only notifications that have been displayed can be cleared

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.clearNotificationByMsgId("your_message_id")
          JPushInterface.clearNotificationByMsgId("your_message_id")

        
This code block is shown in the floating window

Parameter description

  • msgId Message ID, used to specify the notification to be cleared

Clear all notifications (clearNotificationAll)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Function description

  • ClearJiguangAll notifications shown

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.clearNotificationAll()
          JPushInterface.clearNotificationAll()

        
This code block is shown in the floating window

Parameter description

  • none

Message status reporting API

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Report custom message display (reportCustomDisplay)

Function description

  • please firstinit, otherwise the call is invalid

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.reportCustomDisplay(jCustomMessage.channel, jCustomMessage.msgId as string)
          JPushInterface.reportCustomDisplay(jCustomMessage.channel, jCustomMessage.msgId as string)

        
This code block is shown in the floating window

Parameter description

  • channel: Data source channel
    • 0:Manufacturer channel
    • 1: Jiguangaisle
  • msgId: message ID

Click to report a custom message (reportCustomClick)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Function description

  • please firstinit, otherwise the call is invalid

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.reportCustomClick(jCustomMessage.channel, jCustomMessage.msgId as string)
          JPushInterface.reportCustomClick(jCustomMessage.channel, jCustomMessage.msgId as string)

        
This code block is shown in the floating window

Parameter description

  • channel: Data source channel
    • 0:Manufacturer channel
    • 1: Jiguangaisle
  • msgId: message ID

Report notification display (reportNotificationDisplay)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Function description

  • please firstinit, otherwise the call is invalid

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.reportNotificationDisplay(jMessage.channel, jMessage.msgId as string)
          JPushInterface.reportNotificationDisplay(jMessage.channel, jMessage.msgId as string)

        
This code block is shown in the floating window

Parameter description

  • channel: Data source channel
    • 0:Manufacturer channel
    • 1: Jiguangaisle
  • msgId: message ID

Click on the report notification (reportNotificationClick)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Function description

  • please firstinit, otherwise the call is invalid

Interface definition

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

        
This code block is shown in the floating window

code example

JPushInterface.reportNotificationClick(jMessage.channel, jMessage.msgId as string)
          JPushInterface.reportNotificationClick(jMessage.channel, jMessage.msgId as string)

        
This code block is shown in the floating window

Parameter description

  • channel: Data source channel
    • 0:Manufacturer channel
    • 1: Jiguangaisle
  • msgId: message ID

App active duration statistics switch (setEnableAppTerminate)

Function description

  • please firstsetAppKey, otherwise the call is invalid

Interface definition

/** * @param applicationContext 上下文 * @param enable 默认为true,false-不允许统计 * */ setEnableAppTerminate(applicationContext: common.ApplicationContext, enable: boolean)
              /**
     * @param applicationContext 上下文
     * @param enable 默认为truefalse-不允许统计
     *
     */
    setEnableAppTerminate(applicationContext: common.ApplicationContext, enable: boolean)

        
This code block is shown in the floating window

code example

JCollectControl.setEnableAppTerminate(this.context.getApplicationContext(), false)
          JCollectControl.setEnableAppTerminate(this.context.getApplicationContext(), false)

        
This code block is shown in the floating window

Parameter description

  • applicationContext
    • context
  • enable
    • Default istrue,false-Statistics not allowed

wifiList collection switch (setListWifi)

Function description

  • please firstsetAppKey, otherwise the call is invalid

Interface definition

/** * @param applicationContext 上下文 * @param enable 默认为true,false-不允许采集 * */ setListWifi(applicationContext: common.ApplicationContext, enable: boolean)
              /**
     * @param applicationContext 上下文
     * @param enable 默认为truefalse-不允许采集
     *
     */
    setListWifi(applicationContext: common.ApplicationContext, enable: boolean)

        
This code block is shown in the floating window

code example

JCollectControl.setListWifi(this.context.getApplicationContext(), false)
          JCollectControl.setListWifi(this.context.getApplicationContext(), false)

        
This code block is shown in the floating window

Parameter description

  • applicationContext
    • context
  • enable
    • Default istrue,false-Collection is not allowed

set upuser segmentPush switch (setSmartPushEnable)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Function description

controluser segmentPush function switch.user segmentPush is a function of precise push based on user behavior, geographical location and other dimensions.

  • please AbilityStage(#onCreate) called inside
  • please init Called before
  • Optional interface

Interface definition

/** * 设置用户分群推送开关 * @param applicationContext 应用上下文 * @param enable true: 启用用户分群推送功能, false: 禁用用户分群推送功能 */ setSmartPushEnable(applicationContext: common.ApplicationContext, enable: boolean)
              /**
     * 设置用户分群推送开关
     * @param applicationContext 应用上下文
     * @param enable true: 启用用户分群推送功能, false: 禁用用户分群推送功能
     */
    setSmartPushEnable(applicationContext: common.ApplicationContext, enable: boolean)

        
This code block is shown in the floating window

code example

// 启用用户分群推送功能 JPushInterface.setSmartPushEnable(this.context.getApplicationContext(), true) // 禁用用户分群推送功能 JPushInterface.setSmartPushEnable(this.context.getApplicationContext(), false)
          // 启用用户分群推送功能
JPushInterface.setSmartPushEnable(this.context.getApplicationContext(), true)

// 禁用用户分群推送功能
JPushInterface.setSmartPushEnable(this.context.getApplicationContext(), false)

        
This code block is shown in the floating window

Parameter description

  • applicationContext: Application context, used for initializationSDK
  • enable:
    • true: enableuser segmentPush function
    • false: disableuser segmentPush function

Instructions for use

  • user segmentThe push function can help developers make accurate pushes based on user characteristics.
  • It is recommended to enable this feature after the user agrees to the privacy policy
  • This feature is enabled by default

Set the user insights switch (setDataInsightsEnable)

Versions supported starting from:JPush HarmonyOS SDK v1.3.0

Function description

Controls the switch of user behavior data collection function. The user insight function is used to analyze user behavior patterns and provide data support for push strategies.

  • please AbilityStage(#onCreate) called inside
  • please init Called before
  • Optional interface

Interface definition

/** * 设置用户洞察开关 * @param applicationContext 应用上下文 * @param enable true: 允许采集用户行为数据用于用户洞察, false: 不允许采集用户行为数据 */ setDataInsightsEnable(applicationContext: common.ApplicationContext, enable: boolean)
              /**
     * 设置用户洞察开关
     * @param applicationContext 应用上下文
     * @param enable true: 允许采集用户行为数据用于用户洞察, false: 不允许采集用户行为数据
     */
    setDataInsightsEnable(applicationContext: common.ApplicationContext, enable: boolean)

        
This code block is shown in the floating window

code example

// 启用用户洞察功能 JPushInterface.setDataInsightsEnable(this.context.getApplicationContext(), true) // 禁用用户洞察功能 JPushInterface.setDataInsightsEnable(this.context.getApplicationContext(), false)
          // 启用用户洞察功能
JPushInterface.setDataInsightsEnable(this.context.getApplicationContext(), true)

// 禁用用户洞察功能
JPushInterface.setDataInsightsEnable(this.context.getApplicationContext(), false)

        
This code block is shown in the floating window

Parameter description

  • applicationContext: Application context, used for initializationSDK
  • enable:
    • true: Allows collection of user behavior data for user insights
    • false: Do not allow collection of user behavior data

Instructions for use

  • The user insight function collects user usage behavior data to optimize push effects.
  • It is recommended to enable this feature after the user agrees to the privacy policy
  • This feature is enabled by default
  • This feature is the same asuser segmentPush functions are independent of each other and can be controlled separately

GPSCollection switch (setGPS)--(1.3.0version obsolete)

Function description

  • please firstsetAppKey, otherwise the call is invalid

Interface definition

/** * @param applicationContext 上下文 * @param enable 默认为true,false-不允许采集 * */ setGPS(applicationContext: common.ApplicationContext, enable: boolean)
              /**
     * @param applicationContext 上下文
     * @param enable 默认为truefalse-不允许采集
     *
     */
    setGPS(applicationContext: common.ApplicationContext, enable: boolean)

        
This code block is shown in the floating window

code example

JCollectControl.setGPS(this.context.getApplicationContext(), false)
          JCollectControl.setGPS(this.context.getApplicationContext(), false)

        
This code block is shown in the floating window

Parameter description

  • applicationContext
    • context
  • enable
    • Default istrue,false-Collection is not allowed
Was this document helpful?

Copyright 2011-2026, jiguang.cn, All Rights Reserved. 粤ICP备12056275号-13 Shenzhen Hexun Huagu Information Technology Co., Ltd.

Open in Docs Center