openharmony 鸿蒙 common-event-remove-sticky-sys

2026-08-25 浏览 (1)

Removing Sticky Common Events (for System Applications Only)

When to Use

Subscribers can receive sticky common events that have been sent. If the events are no longer forwarded, the event publisher needs to remove them. The system provides an API for removing sticky common events.

Available APIs

For details, see API Reference.

NameDescription
removeStickyCommonEvent(event: string, callback: AsyncCallback<void>): voidRemoves a sticky common event.

How to Develop

  1. Declare the ohos.permission.COMMONEVENT_STICKY permission. For details, see Declaring Permissions.

  2. Import the related modules.

    import { BusinessError, commonEventManager } from '@kit.BasicServicesKit';
    import { hilog } from '@kit.PerformanceAnalysisKit';
    
    const TAG: string = 'ProcessModel';
    const DOMAIN_NUMBER: number = 0xFF00;
    
  3. Call removeStickyCommonEvent() to remove the corresponding sticky common event.

    NOTE

    The sticky common event to be removed must have been released by the application. For details about how to publish sticky common events, see Publishing Common Events.

    // Remove the sticky common event. Replace the event field with the actual event name.
    commonEventManager.removeStickyCommonEvent('event', (err: BusinessError) => {
      // sticky_event indicates the name of the target sticky common event.
      if (err) {
        hilog.error(DOMAIN_NUMBER, TAG, `Failed to remove sticky common event. Code is ${err.code}, message is ${err.message}`);
        return;
      }
      //...
      hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in removing sticky event.`);
    });
    

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 common-event-overview

openharmony 鸿蒙 common-event-publish

openharmony 鸿蒙 native-common-event-unsubscription

openharmony 鸿蒙 native-common-event-publish

openharmony 鸿蒙 Readme-EN

openharmony 鸿蒙 itc-with-emitter

openharmony 鸿蒙 native-common-event-subscription

openharmony 鸿蒙 common-event-static-subscription-sys

openharmony 鸿蒙 common-event-subscription

openharmony 鸿蒙 common-event-unsubscription

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/mjS5dgsX