harmony 鸿蒙Removing Sticky Common Events (for System Applications Only)

  • 2023-06-24
  • 浏览 (634)

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. OpenHarmony provides an API for removing sticky common events.

Available APIs

For details, see Common Event

Name Description
removeStickyCommonEvent(event: string, callback: AsyncCallback<void>): void Removes a sticky common event.

How to Develop

  1. Request the ohos.permission.COMMONEVENT_STICKY permission. For details, see Declaring Permissions in the Configuration File.

  2. Import the module.

   import commonEventManager from '@ohos.commonEventManager';
   import Base from '@ohos.base';
  1. Call the removeStickyCommonEvent() API to remove the target sticky common event.

NOTE

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

   commonEventManager.removeStickyCommonEvent("sticky_event", (err: Base.BusinessError) => { // sticky_event indicates the name of the target sticky common event.
     if (err) {
       console.error(`Failed to remove sticky common event. Code is ${err.code}, message is ${err.message}`);
       return;
     }
     console.info(`Succeeded in removeing sticky event.`);
   });

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Application Models

harmony 鸿蒙Using Explicit Want to Start an Application Component

harmony 鸿蒙Using Implicit Want to Open a Website

harmony 鸿蒙AbilityStage Component Container

harmony 鸿蒙Accessing a DataAbility

harmony 鸿蒙Accessing a DataShareExtensionAbility from the FA Model

harmony 鸿蒙AccessibilityExtensionAbility

harmony 鸿蒙Common action and entities Values

harmony 鸿蒙API Switching Overview

harmony 鸿蒙Switching of app and deviceConfig

0  赞