目录

PushExtensionAbility

PushExtensionAbility is currently in the beta test phase and not open for application. If your app needs to start a subprocess to process services, please refer to Pushing an Extended Notification Message.

PushExtensionAbility provides callbacks for obtaining scenario-specific message data and destroying the lifecycle. The restrictions are as follows:

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Push.PushService

Start version: 4.0.0(10)

Module Import

import { PushExtensionAbility } from '@kit.PushKit';

Attributes

Model restriction: The attributes can be used only in the stage model.

System capability: SystemCapability.Push.PushService

Start version: 4.0.0(10)

Name

Type

Read-only

Optional

Description

context

PushExtensionContext

No

No

Context of PushExtensionAbility, which inherits from ExtensionContext.

onReceiveMessage

onReceiveMessage(payload: pushCommon.PushPayload): void

API for receiving scenario-specific messages after an app inherits from PushExtensionAbility.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Push.PushService

Start version: 4.0.0(10)

Parameters:

Parameter

Type

Optional

Description

payload

pushCommon.PushPayload

No

Scenario-specific message data.

Example:

import { PushExtensionAbility, pushCommon } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

// In the following example, TestExtAbility inherits from PushExtensionAbility:
export default class TestExtAbility extends PushExtensionAbility {
  onReceiveMessage(payload: pushCommon.PushPayload): void {
    hilog.info(0x0000, 'testTag', 'TestExtAbility onReceiveMessage');
  }
}

onDestroy

onDestroy(): void

This callback is executed when the PushExtensionAbility lifecycle ends. You are advised to clear resources in this method.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Push.PushService

Start version: 4.0.0(10)

Example:

import { PushExtensionAbility } from '@kit.PushKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

// In the following example, TestExtAbility inherits from PushExtensionAbility:
export default class TestExtAbility extends PushExtensionAbility {
  onDestroy(): void {
    hilog.info(0x0000, 'testTag', 'TestExtAbility onDestroy');
  }
}