@ohos.notificationManager (NotificationManager) (System API)

The NotificationManager module provides notification management capabilities, covering notifications, notification slots, notification enabled status, and notification badge status.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

This topic describes only system APIs provided by the module. For details about its public APIs, see NotificationManager.

Modules to Import

import { notificationManager } from '@kit.NotificationKit';

notificationManager.publish

publish(request: NotificationRequest, userId: number, callback: AsyncCallback<void>): void

Publishes a notification to a specified user. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.SEND_NOTIFICATION_CROSS_USER

System API: This is a system API.

Parameters

Name Type Mandatory Description
request NotificationRequest Yes Content and related configuration of the notification to publish.
userId number Yes User ID.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and HTTP Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 The device does not support geofencing.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600004 Notification disabled.
1600005 Notification slot disabled.
1600007 The notification does not exist.
1600008 The user does not exist.
1600009 The notification sending frequency reaches the upper limit.
1600012 No memory space.
1600014 No permission.
1600015 The current notification status does not support duplicate configurations.
1600016 The notification version for this update is too low.
1600020 The application is not allowed to send notifications due to permission settings.
1600025 Geofencing disabled.
1600026 The location switch is off.
1600027 The "Awareness & suggestions" switch of the location-based service is off.
2300007 Network unreachable.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// publish callback
let publishCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`publish failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("publish success");
    }
}
// Use the actual user ID when calling the API.
let userId: number = 1;
// NotificationRequest object
let notificationRequest: notificationManager.NotificationRequest = {
    id: 1,
    content: {
        notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
};
notificationManager.publish(notificationRequest, userId, publishCallback);

notificationManager.publish

publish(request: NotificationRequest, userId: number): Promise<void>

Publishes a notification to a specified user. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.SEND_NOTIFICATION_CROSS_USER

System API: This is a system API.

Parameters

Name Type Mandatory Description
request NotificationRequest Yes Content and related configuration of the notification to publish.
userId number Yes User ID.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and HTTP Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 The device does not support geofencing.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600004 Notification disabled.
1600005 Notification slot disabled.
1600007 The notification does not exist.
1600008 The user does not exist.
1600009 The notification sending frequency reaches the upper limit.
1600012 No memory space.
1600014 No permission.
1600015 The current notification status does not support duplicate configurations.
1600016 The notification version for this update is too low.
1600020 The application is not allowed to send notifications due to permission settings.
1600025 Geofencing disabled.
1600026 The location switch is off.
1600027 The "Awareness & suggestions" switch of the location-based service is off.
2300007 Network unreachable.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let notificationRequest: notificationManager.NotificationRequest = {
    id: 1,
    content: {
        notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
};

// Use the actual user ID when calling the API.
let userId: number = 1;

notificationManager.publish(notificationRequest, userId).then(() => {
    console.info("publish success");
}).catch((err: BusinessError) => {
    console.error(`publish failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.addSlot

addSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void

Adds a notification slot. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
slot NotificationSlot Yes Notification slot to add.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// addSlot callback
let addSlotCallBack = (err: BusinessError): void => {
    if (err) {
        console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("addSlot success");
    }
}
// NotificationSlot object
let notificationSlot: notificationManager.NotificationSlot = {
    notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
notificationManager.addSlot(notificationSlot, addSlotCallBack);

notificationManager.addSlot

addSlot(slot: NotificationSlot): Promise<void>

Adds a notification slot. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
slot NotificationSlot Yes Notification slot to add.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// NotificationSlot object
let notificationSlot: notificationManager.NotificationSlot = {
    notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
notificationManager.addSlot(notificationSlot).then(() => {
    console.info("addSlot success");
}).catch((err: BusinessError) => {
    console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.addSlots

addSlots(slots: Array<NotificationSlot>, callback: AsyncCallback<void>): void

Adds an array of notification slots. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
slots Array<NotificationSlot> Yes Notification slots to add. The number of elements in the array ranges from 0 to 5.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// addSlots callback
let addSlotsCallBack = (err: BusinessError): void => {
    if (err) {
        console.error(`addSlots failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("addSlots success");
    }
}
// NotificationSlot object
let notificationSlot: notificationManager.NotificationSlot = {
    notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
// NotificationSlotArray object
let notificationSlotArray: notificationManager.NotificationSlot[] = new Array();
notificationSlotArray[0] = notificationSlot;

notificationManager.addSlots(notificationSlotArray, addSlotsCallBack);

notificationManager.addSlots

addSlots(slots: Array<NotificationSlot>): Promise<void>

Adds an array of notification slots. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
slots Array<NotificationSlot> Yes Notification slots to add. The number of elements in the array ranges from 0 to 5.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// NotificationSlot object
let notificationSlot: notificationManager.NotificationSlot = {
    notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
// NotificationSlotArray object
let notificationSlotArray: notificationManager.NotificationSlot[] = new Array();
notificationSlotArray[0] = notificationSlot;

notificationManager.addSlots(notificationSlotArray).then(() => {
    console.info("addSlots success");
}).catch((err: BusinessError) => {
    console.error(`addSlots failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setNotificationEnable

setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback<void>): void

Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
enable boolean Yes Whether to enable the notification slot type. The value true means to enable the notification slot type, and false means the opposite.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let setNotificationEnableCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`setNotificationEnable failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("setNotificationEnable success");
    }
}
let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.setNotificationEnable(bundle, false, setNotificationEnableCallback);

notificationManager.setNotificationEnable

setNotificationEnable(bundle: BundleOption, enable: boolean): Promise<void>

Sets whether to enable notification for a specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
enable boolean Yes Whether to enable the notification slot type. The value true means to enable the notification slot type, and false means the opposite.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.setNotificationEnable(bundle, false).then(() => {
    console.info("setNotificationEnable success");
}).catch((err: BusinessError) => {
    console.error(`setNotificationEnable failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getAllNotificationEnabledBundles12+

getAllNotificationEnabledBundles(): Promise<Array<BundleOption>>

Obtains a list of applications that allow notifications. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Return value

Type Description
Promise<Array<BundleOption>> Returns a list of applications that allow notifications.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.getAllNotificationEnabledBundles().then((data: Array<notificationManager.BundleOption>) => {
    console.info(`Enable bundle data is ${JSON.stringify(data)}`);
    data.forEach(element => {
        console.info(`Enable uid is ${JSON.stringify(element.uid)}`);
        console.info(`Enable bundle is ${JSON.stringify(element.bundle)}`);
    });
}).catch((err: BusinessError) => {
    console.error(`getAllNotificationEnabledBundles failed, code is ${err.code}, message is ${err.message}`);
})

notificationManager.getAllNotificationEnabledBundles23+

getAllNotificationEnabledBundles(userId: number): Promise<Array<BundleOption>>

Obtains the list of applications that are allowed to publish notifications by a specified user. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
userId number Yes Target user.

Return value

Type Description
Promise<Array<BundleOption>> Returns a list of applications that allow notifications.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let userId : number = 100;

notificationManager.getAllNotificationEnabledBundles(userId).then((data: Array<notificationManager.BundleOption>) => {
  console.info(`Enable bundle data is ${JSON.stringify(data)}`);
  data.forEach(element => {
    console.info(`Enable uid is ${JSON.stringify(element.uid)}`);
    console.info(`Enable bundle is ${JSON.stringify(element.bundle)}`);
  });
}).catch((err: BusinessError) => {
  console.error(`getAllNotificationEnabledBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isNotificationEnabled

isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback<boolean>): void

Checks whether notification is enabled for the specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means that the notification is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let isNotificationEnabledCallback = (err: BusinessError, data: boolean): void => {
    if (err) {
        console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`isNotificationEnabled success, data is ${JSON.stringify(data)}`);
    }
}

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};

notificationManager.isNotificationEnabled(bundle, isNotificationEnabledCallback);

notificationManager.isNotificationEnabled

isNotificationEnabled(bundle: BundleOption): Promise<boolean>

Checks whether notification is enabled for the specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that the notification is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.isNotificationEnabled(bundle).then((data: boolean) => {
    console.info(`isNotificationEnabled success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isNotificationEnabled

isNotificationEnabled(userId: number, callback: AsyncCallback<boolean>): void

Checks whether notification is enabled for a specified user. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
userId number Yes User ID.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means that the notification is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let isNotificationEnabledCallback = (err: BusinessError, data: boolean): void => {
    if (err) {
        console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`isNotificationEnabled success, data is ${JSON.stringify(data)}`);
    }
}

// Use the actual user ID when calling the API.
let userId: number = 1;

notificationManager.isNotificationEnabled(userId, isNotificationEnabledCallback);

notificationManager.isNotificationEnabled

isNotificationEnabled(userId: number): Promise<boolean>

Checks whether notification is enabled for a specified user. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
userId number Yes User ID.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that the notification is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Use the actual user ID when calling the API.
let userId: number = 1;

notificationManager.isNotificationEnabled(userId).then((data: boolean) => {
    console.info(`isNotificationEnabled success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.displayBadge

displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback<void>): void

Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
enable boolean Yes Whether to enable the notification slot type. The value true means to enable the notification slot type, and false means the opposite.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let displayBadgeCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`displayBadge failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("displayBadge success");
    }
}
let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.displayBadge(bundle, false, displayBadgeCallback);

notificationManager.displayBadge

displayBadge(bundle: BundleOption, enable: boolean): Promise<void>

Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
enable boolean Yes Whether to enable the notification slot type. The value true means to enable the notification slot type, and false means the opposite.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.displayBadge(bundle, false).then(() => {
    console.info("displayBadge success");
}).catch((err: BusinessError) => {
    console.error(`displayBadge failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isBadgeDisplayed

isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback<boolean>): void

Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means that the badge is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let isBadgeDisplayedCallback = (err: BusinessError, data: boolean): void => {
    if (err) {
        console.error(`isBadgeDisplayed failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`isBadgeDisplayed success, data is ${JSON.stringify(data)}`);
    }
}
let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.isBadgeDisplayed(bundle, isBadgeDisplayedCallback);

notificationManager.isBadgeDisplayed

isBadgeDisplayed(bundle: BundleOption): Promise<boolean>

Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that the badge is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
  bundle: "bundleName1",
};

notificationManager.isBadgeDisplayed(bundle).then((data: boolean) => {
    console.info(`isBadgeDisplayed success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`isBadgeDisplayed failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setSlotFlagsByBundle11+

setSlotFlagsByBundle(bundle: BundleOption, slotFlags: number): Promise<void>

Sets the slot flags for a specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
slotFlags number Yes Notification slot flags.
- Bit 0: sound alert. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 1: locking the screen. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 2: banner. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 3: turning on the screen. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 4: vibration. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 5: notification icon in the status bar. The value 0 means to disable the feature, and 1 means the opposite.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};

let slotFlags: number = 1;

notificationManager.setSlotFlagsByBundle(bundle, slotFlags).then(() => {
    console.info("setSlotFlagsByBundle success");
}).catch((err: BusinessError) => {
    console.error(`setSlotFlagsByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setSlotByBundle

setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback<void>): void

Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result.

Before setting a notification slot, create a slot through addSlot.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
slot NotificationSlot Yes Notification slot.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let setSlotByBundleCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`setSlotByBundle failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("setSlotByBundle success");
    }
}
let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
let notificationSlot: notificationManager.NotificationSlot = {
    notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
notificationManager.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback);

notificationManager.setSlotByBundle

setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise<void>

Sets the notification slot for a specified application. This API uses a promise to return the result.

Before setting a notification slot, create a slot through addSlot.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
slot NotificationSlot Yes Notification slot.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};

let notificationSlot: notificationManager.NotificationSlot = {
    notificationType: notificationManager.SlotType.SOCIAL_COMMUNICATION
};

notificationManager.setSlotByBundle(bundle, notificationSlot).then(() => {
    console.info("setSlotByBundle success");
}).catch((err: BusinessError) => {
    console.error(`setSlotByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getSlotFlagsByBundle11+

getSlotFlagsByBundle(bundle: BundleOption): Promise<number>

Obtains the notification slot flag of a specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.

Return value

Type Description
Promise<number> Promise used to return the notification slot flag.
- Bit 0: sound alert. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 1: locking the screen. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 2: banner. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 3: turning on the screen. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 4: vibration. The value 0 means to disable the feature, and 1 means the opposite.
- Bit 5: notification icon in the status bar. The value 0 means to disable the feature, and 1 means the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.getSlotFlagsByBundle(bundle).then((data : number) => {
    console.info(`getSlotFlagsByBundle success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getSlotFlagsByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getSlotsByBundle

getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array<NotificationSlot>>): void

Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
callback AsyncCallback<Array<NotificationSlot>> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let getSlotsByBundleCallback = (err: BusinessError, data: Array<notificationManager.NotificationSlot>): void => {
    if (err) {
        console.error(`getSlotsByBundle failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`getSlotsByBundle success, data is ${JSON.stringify(data)}`);
    }
}
let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.getSlotsByBundle(bundle, getSlotsByBundleCallback);

notificationManager.getSlotsByBundle

getSlotsByBundle(bundle: BundleOption): Promise<Array<NotificationSlot>>

Obtains the notification slots of a specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.

Return value

Type Description
Promise<Array<NotificationSlot>> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};

notificationManager.getSlotsByBundle(bundle).then((data: Array<notificationManager.NotificationSlot>) => {
     console.info(`getSlotsByBundle success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getSlotsByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getSlotNumByBundle

getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback<number>): void

Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
callback AsyncCallback<number> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let getSlotNumByBundleCallback = (err: BusinessError, data: number): void => {
    if (err) {
        console.error(`getSlotNumByBundle failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`getSlotNumByBundle success data is ${JSON.stringify(data)}`);
    }
}

let bundle: notificationManager.BundleOption = {
  bundle: "bundleName1",
};

notificationManager.getSlotNumByBundle(bundle, getSlotNumByBundleCallback);

notificationManager.getSlotNumByBundle

getSlotNumByBundle(bundle: BundleOption): Promise<number>

Obtains the number of notification slots of a specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.

Return value

Type Description
Promise<number> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
  bundle: "bundleName1",
};

notificationManager.getSlotNumByBundle(bundle).then((data: number) => {
    console.info(`getSlotNumByBundle success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getSlotNumByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getAllActiveNotifications

getAllActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>): void

Obtains all active notifications. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
callback AsyncCallback<Array<NotificationRequest>> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let getAllActiveNotificationsCallback = (err: BusinessError, data: Array<notificationManager.NotificationRequest>): void => {
    if (err) {
        console.error(`getAllActiveNotifications failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`getAllActiveNotifications success, data is ${JSON.stringify(data)}`);
    }
}

notificationManager.getAllActiveNotifications(getAllActiveNotificationsCallback);

notificationManager.getAllActiveNotifications

getAllActiveNotifications(): Promise<Array<NotificationRequest>>

Obtains all active notifications. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Return value

Type Description
Promise<Array<NotificationRequest>> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.getAllActiveNotifications().then((data: Array<notificationManager.NotificationRequest>) => {
    console.info(`getAllActiveNotifications success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getAllActiveNotifications failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getActiveNotificationByFilter11+

getActiveNotificationByFilter(filter: NotificationFilter, callback: AsyncCallback<NotificationRequest>): void

Obtains information about the common live view that matches the specified filter criteria. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
filter NotificationFilter Yes Filter criteria for querying the common live view.
callback AsyncCallback<NotificationRequest> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600007 The notification does not exist.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { notificationSubscribe } from '@kit.NotificationKit';

let bundleOption: notificationManager.BundleOption = {
  bundle: "bundleName1",
};
let notificationKey: notificationSubscribe.NotificationKey = {
    id: 11,
    label: ""
};
let filter: notificationManager.NotificationFilter = {
    bundle: bundleOption,
    notificationKey: notificationKey,
    extraInfoKeys: ['event']
}
let getActiveNotificationByFilterCallback = (err: BusinessError, data: notificationManager.NotificationRequest): void => {
    if (err) {
        console.error(`getActiveNotificationByFilter failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("getActiveNotificationByFilter success");
    }
}
notificationManager.getActiveNotificationByFilter(filter, getActiveNotificationByFilterCallback);

notificationManager.getActiveNotificationByFilter11+

getActiveNotificationByFilter(filter: NotificationFilter): Promise<NotificationRequest>

Obtains information about the common live view that matches the specified filter criteria. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
filter NotificationFilter Yes Filter criteria for querying the common live view.

Return value

Type Description
Promise<NotificationRequest> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600007 The notification does not exist.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { notificationSubscribe } from '@kit.NotificationKit';

let bundleOption: notificationManager.BundleOption = {
  bundle: "bundleName1",
};
let notificationKey: notificationSubscribe.NotificationKey = {
    id: 11,
    label: ""
};
let filter: notificationManager.NotificationFilter = {
    bundle: bundleOption,
    notificationKey: notificationKey,
    extraInfoKeys: ['event']
}
notificationManager.getActiveNotificationByFilter(filter).then((data: notificationManager.NotificationRequest) => {
    console.info(`getActiveNotificationByFilter success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getActiveNotificationByFilter failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.removeGroupByBundle

removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback<void>): void

Removes notifications under a notification group of the specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
groupName string Yes Name of the notification group.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let removeGroupByBundleCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("removeGroupByBundle success");
    }
}

let bundleOption: notificationManager.BundleOption = { bundle: "Bundle" };
let groupName: string = "GroupName";

notificationManager.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback);

notificationManager.removeGroupByBundle

removeGroupByBundle(bundle: BundleOption, groupName: string): Promise<void>

Removes notifications under a notification group of the specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
groupName string Yes Name of the notification group.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundleOption: notificationManager.BundleOption = { bundle: "Bundle" };
let groupName: string = "GroupName";

notificationManager.removeGroupByBundle(bundleOption, groupName).then(() => {
    console.info("removeGroupByBundle success");
}).catch((err: BusinessError) => {
    console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setDoNotDisturbDate

setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback<void>): void

Sets the DND time. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
date DoNotDisturbDate Yes DND time to set.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let setDoNotDisturbDateCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("setDoNotDisturbDate success");
    }
}

let doNotDisturbDate: notificationManager.DoNotDisturbDate = {
    type: notificationManager.DoNotDisturbType.TYPE_ONCE,
    begin: new Date(),
    end: new Date(2021, 11, 15, 18, 0)
};

notificationManager.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback);

notificationManager.setDoNotDisturbDate

setDoNotDisturbDate(date: DoNotDisturbDate): Promise<void>

Sets the DND time. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
date DoNotDisturbDate Yes DND time to set.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let doNotDisturbDate: notificationManager.DoNotDisturbDate = {
    type: notificationManager.DoNotDisturbType.TYPE_ONCE,
    begin: new Date(),
    end: new Date(2021, 11, 15, 18, 0)
};
notificationManager.setDoNotDisturbDate(doNotDisturbDate).then(() => {
    console.info("setDoNotDisturbDate success");
}).catch((err: BusinessError) => {
    console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setDoNotDisturbDate

setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback<void>): void

Sets the DND time for a specified user. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
date DoNotDisturbDate Yes DND time to set.
userId number Yes ID of the user for whom you want to set the DND time.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let setDoNotDisturbDateCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("setDoNotDisturbDate success");
    }
}

let doNotDisturbDate: notificationManager.DoNotDisturbDate = {
    type: notificationManager.DoNotDisturbType.TYPE_ONCE,
    begin: new Date(),
    end: new Date(2021, 11, 15, 18, 0)
};

// Use the actual user ID when calling the API.
let userId: number = 1;

notificationManager.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback);

notificationManager.setDoNotDisturbDate

setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise<void>

Sets the DND time for a specified user. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
date DoNotDisturbDate Yes DND time to set.
userId number Yes ID of the user for whom you want to set the DND time.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let doNotDisturbDate: notificationManager.DoNotDisturbDate = {
    type: notificationManager.DoNotDisturbType.TYPE_ONCE,
    begin: new Date(),
    end: new Date(2021, 11, 15, 18, 0)
};

// Use the actual user ID when calling the API.
let userId: number = 1;

notificationManager.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => {
    console.info("setDoNotDisturbDate success");
}).catch((err: BusinessError) => {
    console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getDoNotDisturbDate

getDoNotDisturbDate(callback: AsyncCallback<DoNotDisturbDate>): void

Obtains the DND time. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
callback AsyncCallback<DoNotDisturbDate> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let getDoNotDisturbDateCallback = (err: BusinessError, data: notificationManager.DoNotDisturbDate): void => {
    if (err) {
        console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`getDoNotDisturbDate success, data is ${JSON.stringify(data)}`);
    }
}

notificationManager.getDoNotDisturbDate(getDoNotDisturbDateCallback);

notificationManager.getDoNotDisturbDate

getDoNotDisturbDate(): Promise<DoNotDisturbDate>

Obtains the DND time. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Return value

Type Description
Promise<DoNotDisturbDate> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.getDoNotDisturbDate().then((data: notificationManager.DoNotDisturbDate) => {
  console.info(`getDoNotDisturbDate success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getDoNotDisturbDate

getDoNotDisturbDate(userId: number, callback: AsyncCallback<DoNotDisturbDate>): void

Obtains the DND time of a specified user. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
callback AsyncCallback<DoNotDisturbDate> Yes Callback used to return the result.
userId number Yes User ID.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let getDoNotDisturbDateCallback = (err: BusinessError, data: notificationManager.DoNotDisturbDate): void => {
    if (err) {
        console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`getDoNotDisturbDate success, data is ${JSON.stringify(data)}`);
    }
}

// Use the actual user ID when calling the API.
let userId: number = 1;

notificationManager.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback);

notificationManager.getDoNotDisturbDate

getDoNotDisturbDate(userId: number): Promise<DoNotDisturbDate>

Obtains the DND time of a specified user. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
userId number Yes User ID.

Return value

Type Description
Promise<DoNotDisturbDate> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Use the actual user ID when calling the API.
let userId: number = 1;

notificationManager.getDoNotDisturbDate(userId).then((data: notificationManager.DoNotDisturbDate) => {
    console.info(`getDoNotDisturbDate success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isSupportDoNotDisturbMode

isSupportDoNotDisturbMode(callback: AsyncCallback<boolean>): void

Checks whether DND mode is supported. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means that DND mode is supported, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let isSupportDoNotDisturbModeCallback = (err: BusinessError, data: boolean): void => {
    if (err) {
        console.error(`isSupportDoNotDisturbMode failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`isSupportDoNotDisturbMode success, data: ${JSON.stringify(data)}`);
    }
}

notificationManager.isSupportDoNotDisturbMode(isSupportDoNotDisturbModeCallback);

notificationManager.isSupportDoNotDisturbMode

isSupportDoNotDisturbMode(): Promise<boolean>

Checks whether DND mode is supported. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that DND mode is supported, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.isSupportDoNotDisturbMode().then((data: boolean) => {
    console.info(`isSupportDoNotDisturbMode success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`isSupportDoNotDisturbMode failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setDistributedEnable(deprecated)

setDistributedEnable(enable: boolean, callback: AsyncCallback<void>): void

Sets whether to enable distributed notification on this device. This API uses an asynchronous callback to return the result.

Since: 9

Deprecated since: 26.0.0

Substitutes:: setDistributedEnabled

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
enable boolean Yes Whether to enable distributed notification. The value true means to enable distributed notification, and false means the opposite.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let setDistributedEnableCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`setDistributedEnable failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("setDistributedEnable success");
    }
};
let enable: boolean = true;
notificationManager.setDistributedEnable(enable, setDistributedEnableCallback);

notificationManager.setDistributedEnable(deprecated)

setDistributedEnable(enable: boolean): Promise<void>

Sets whether to enable distributed notification on this device. This API uses a promise to return the result.

Since: 9

Deprecated since: 26.0.0

Substitutes:: setDistributedEnabled

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
enable boolean Yes Whether to enable distributed notification. The value true means to enable distributed notification, and false means the opposite.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let enable: boolean = true;
notificationManager.setDistributedEnable(enable).then(() => {
    console.info("setDistributedEnable success");
}).catch((err: BusinessError) => {
    console.error(`setDistributedEnable failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setDistributedEnableByBundle(deprecated)

setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback<void>): void

Sets whether to enable distributed notification for a specified application. This API uses an asynchronous callback to return the result.

Since: 9

Deprecated since: 26.0.0

Substitutes: [setDistributedEnabledByBundle] (#notificationmanagersetdistributedenabledbybundle12)

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
enable boolean Yes Whether to enable distributed notification. The value true means to enable distributed notification, and false means the opposite.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let setDistributedEnableByBundleCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`setDistributedEnableByBundle failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("setDistributedEnableByBundle success");
    }
};
let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
let enable: boolean = true;
notificationManager.setDistributedEnableByBundle(bundle, enable, setDistributedEnableByBundleCallback);

notificationManager.setDistributedEnableByBundle(deprecated)

setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise<void>

Sets whether to enable distributed notification for a specified application. This API uses a promise to return the result.

Since: 9

Deprecated since: 26.0.0

Substitutes: [setDistributedEnabledByBundle] (#notificationmanagersetdistributedenabledbybundle12)

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle of the application.
enable boolean Yes Whether to enable distributed notification. The value true means to enable distributed notification, and false means the opposite.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
let enable: boolean = true;
notificationManager.setDistributedEnableByBundle(bundle, enable).then(() => {
    console.info("setDistributedEnableByBundle success");
}).catch((err: BusinessError) => {
    console.error(`setDistributedEnableByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isDistributedEnabledByBundle(deprecated)

isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback<boolean>): void

Checks whether distributed notification is enabled for a specified application. This API uses an asynchronous callback to return the result.

Since: 9

Deprecated since: 26.0.0

Substitutes: [isDistributedEnabledByBundle] (#notificationmanagerisdistributedenabledbybundle12)

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle of the application.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means that distributed notification is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let isDistributedEnabledByBundleCallback = (err: BusinessError, data: boolean): void => {
    if (err) {
        console.error(`isDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`isDistributedEnabledByBundle success, data: ${JSON.stringify(data)}`);
    }
};
let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCallback);

notificationManager.isDistributedEnabledByBundle(deprecated)

isDistributedEnabledByBundle(bundle: BundleOption): Promise<boolean>

Checks whether distributed notification is enabled for a specified application. This API uses a promise to return the result.

Since: 9

Deprecated since: 26.0.0

Substitutes: [isDistributedEnabledByBundle] (#notificationmanagerisdistributedenabledbybundle12)

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle of the application.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that distributed notification is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.isDistributedEnabledByBundle(bundle).then((data: boolean) => {
    console.info(`isDistributedEnabledByBundle success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`isDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getDeviceRemindType(deprecated)

getDeviceRemindType(callback: AsyncCallback<DeviceRemindType>): void

Obtains the notification reminder type. This API uses an asynchronous callback to return the result.

Since: 9

Deprecated since: 26.0.0

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
callback AsyncCallback<DeviceRemindType> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let getDeviceRemindTypeCallback = (err: BusinessError, data: notificationManager.DeviceRemindType): void => {
    if (err) {
        console.error(`getDeviceRemindType failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`getDeviceRemindType success, data is ${JSON.stringify(data)}`);
    }
};
notificationManager.getDeviceRemindType(getDeviceRemindTypeCallback);

notificationManager.getDeviceRemindType(deprecated)

getDeviceRemindType(): Promise<DeviceRemindType>

Obtains the notification reminder type. This API uses a promise to return the result.

Since: 9

Deprecated since: 26.0.0

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Return value

Type Description
Promise<DeviceRemindType> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.getDeviceRemindType().then((data: notificationManager.DeviceRemindType) => {
    console.info(`getDeviceRemindType success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getDeviceRemindType failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.publishAsBundle

publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback<void>): void

Publishes a notification through the reminder agent. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
request NotificationRequest Yes Content and related configuration of the notification to publish.
representativeBundle string Yes Bundle name of the application whose notification function is taken over by the reminder agent.
userId number Yes User ID.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and HTTP Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 The device does not support geofencing.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600004 Notification disabled.
1600005 Notification slot disabled.
1600007 The notification does not exist.
1600008 The user does not exist.
1600009 The notification sending frequency reaches the upper limit.
1600012 No memory space.
1600015 The current notification status does not support duplicate configurations.
1600016 The notification version for this update is too low.
1600020 The application is not allowed to send notifications due to permission settings.
1600025 Geofencing disabled.
1600026 The location switch is off.
1600027 The "Awareness & suggestions" switch of the location-based service is off.
2300007 Network unreachable.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// publishAsBundle callback
let callback = (err: BusinessError): void => {
    if (err) {
        console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("publishAsBundle success");
    }
}
// Bundle name of the application whose notification function is taken over by the reminder agent
let representativeBundle: string = "com.example.demo";
// Use the actual user ID when calling the API.
let userId: number = 100;
// NotificationRequest object
let request: notificationManager.NotificationRequest = {
    id: 1,
    content: {
        notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
};
notificationManager.publishAsBundle(request, representativeBundle, userId, callback);

notificationManager.publishAsBundle

publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise<void>

Publishes a notification through the reminder agent. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
request NotificationRequest Yes Content and related configuration of the notification to publish.
representativeBundle string Yes Bundle name of the application whose notification function is taken over by the reminder agent.
userId number Yes User ID.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and HTTP Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 The device does not support geofencing.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600004 Notification disabled.
1600005 Notification slot disabled.
1600007 The notification does not exist.
1600008 The user does not exist.
1600009 The notification sending frequency reaches the upper limit.
1600012 No memory space.
1600015 The current notification status does not support duplicate configurations.
1600016 The notification version for this update is too low.
1600020 The application is not allowed to send notifications due to permission settings.
1600025 Geofencing disabled.
1600026 The location switch is off.
1600027 The "Awareness & suggestions" switch of the location-based service is off.
2300007 Network unreachable.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Bundle name of the application whose notification function is taken over by the reminder agent
let representativeBundle: string = "com.example.demo";
// Use the actual user ID when calling the API.
let userId: number = 100;
// NotificationRequest object
let request: notificationManager.NotificationRequest = {
    id: 1,
    content: {
        notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
};
notificationManager.publishAsBundle(request, representativeBundle, userId).then(() => {
    console.info("publishAsBundle success");
}).catch((err: BusinessError) => {
    console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.publishAsBundle12+

publishAsBundle(representativeBundle: BundleOption, request: NotificationRequest): Promise<void>

Publishes a notification through the reminder agent. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
representativeBundle BundleOption Yes Bundle information of the application whose notification function is taken over by the reminder agent.
request NotificationRequest Yes Content and related configuration of the notification to publish.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and HTTP Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 The device does not support geofencing.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600004 Notification disabled.
1600005 Notification slot disabled.
1600007 The notification does not exist.
1600008 The user does not exist.
1600009 The notification sending frequency reaches the upper limit.
1600012 No memory space.
1600015 The current notification status does not support duplicate configurations.
1600016 The notification version for this update is too low.
1600020 The application is not allowed to send notifications due to permission settings.
1600025 Geofencing disabled.
1600026 The location switch is off.
1600027 The "Awareness & suggestions" switch of the location-based service is off.
2300007 Network unreachable.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Bundle information of the application whose notification function is taken over by the reminder agent.
let representativeBundle: notificationManager.BundleOption = {
  bundle: "bundleName1",
};
// NotificationRequest object
let request: notificationManager.NotificationRequest = {
    id: 1,
    content: {
        notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
        normal: {
            title: "test_title",
            text: "test_text",
            additionalText: "test_additionalText"
        }
    }
};
notificationManager.publishAsBundle(representativeBundle, request).then(() => {
    console.info("publishAsBundle success");
}).catch((err: BusinessError) => {
    console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.cancelAsBundle

cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback<void>): void

Cancels a notification published through the reminder agent. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
id number Yes Notification ID.
representativeBundle string Yes Bundle name of the application whose notification function is taken over by the reminder agent.
userId number Yes User ID.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600007 The notification does not exist.
1600008 The user does not exist.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// cancelAsBundle
let cancelAsBundleCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("cancelAsBundle success");
    }
}
// Bundle name of the application whose notification function is taken over by the reminder agent
let representativeBundle: string = "com.example.demo";
// Use the actual user ID when calling the API.
let userId: number = 100;
notificationManager.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback);

notificationManager.cancelAsBundle

cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise<void>

Cancels a notification published through the reminder agent. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
id number Yes Notification ID.
representativeBundle string Yes Bundle name of the application whose notification function is taken over by the reminder agent.
userId number Yes User ID.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600007 The notification does not exist.
1600008 The user does not exist.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Bundle name of the application whose notification function is taken over by the reminder agent
let representativeBundle: string = "com.example.demo";
// Use the actual user ID when calling the API.
let userId: number = 100;
notificationManager.cancelAsBundle(0, representativeBundle, userId).then(() => {
    console.info("cancelAsBundle success");
}).catch((err: BusinessError) => {
    console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.cancelAsBundle12+

cancelAsBundle(representativeBundle: BundleOption, id: number): Promise<void>

Cancels a notification published through the reminder agent. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
representativeBundle BundleOption Yes Bundle information of the application whose notification function is taken over by the reminder agent.
id number Yes Notification ID.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600007 The notification does not exist.
1600008 The user does not exist.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let representativeBundle: notificationManager.BundleOption = {
  bundle: "bundleName1",
};
notificationManager.cancelAsBundle(representativeBundle, 1).then(() => {
    console.info("cancelAsBundle success");
}).catch((err: BusinessError) => {
    console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.cancel12+

cancel(representativeBundle: BundleOption, id: number): Promise<void>

Cancels the notification of other applications of the user. This API uses a promise to return the result.

The current application must have a proxy relationship with another application, or the ohos.permission.NOTIFICATION_AGENT_CONTROLLER permission is granted to the current application.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Parameters

Name Type Mandatory Description
representativeBundle BundleOption Yes Bundle information of the application.
id number Yes Notification ID.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600007 The notification does not exist.
1600012 No memory space.
1600017 There is no corresponding agent relationship configuration.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
  bundle: "bundleName"
};
let id: number = 1;
notificationManager.cancel(bundle, id).then(() => {
  console.info("cancel success");
}).catch((err: BusinessError) => {
  console.error(`cancel failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setNotificationEnableSlot

setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback<void>): void

Sets the enabled status of a slot type for the specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
type SlotType Yes Notification slot type.
enable boolean Yes Whether to enable the notification slot type. The value true means to enable the notification slot type, and false means the opposite.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// setNotificationEnableSlot
let setNotificationEnableSlotCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("setNotificationEnableSlot success");
    }
};
notificationManager.setNotificationEnableSlot(
    { bundle: "ohos.samples.notification", },
    notificationManager.SlotType.SOCIAL_COMMUNICATION,
    true,
    setNotificationEnableSlotCallback);

notificationManager.setNotificationEnableSlot11+

setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, isForceControl: boolean, callback: AsyncCallback<void>): void

Sets the enabled status of a slot type for the specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
type SlotType Yes Notification slot type.
enable boolean Yes Whether to enable the notification slot type. The value true means to enable the notification slot type, and false means the opposite.
isForceControl11+ boolean Yes Whether the slot is affected by the notification authorization. The value true means the slot is affected, and false means the opposite.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let setNotificationEnableSlotCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("setNotificationEnableSlot success");
    }
};

notificationManager.setNotificationEnableSlot(
    { bundle: "ohos.samples.notification", },
    notificationManager.SlotType.SOCIAL_COMMUNICATION,
    true,
    false,
    setNotificationEnableSlotCallback);

notificationManager.setNotificationEnableSlot

setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, isForceControl?: boolean): Promise<void>

Sets the enabled status of a slot type for the specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
type SlotType Yes Notification slot type.
enable boolean Yes Whether to enable the notification slot type. The value true means to enable the notification slot type, and false means the opposite.
isForceControl11+ boolean No Whether the enabled status of the notification slot is subject to the enabled status of notification. The value false means that the enabled status of the notification slot is subject to the enabled status of notification, and true means the opposite. Default value: false

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// setNotificationEnableSlot
notificationManager.setNotificationEnableSlot(
    { bundle: "ohos.samples.notification", },
    notificationManager.SlotType.SOCIAL_COMMUNICATION,
    true).then(() => {
        console.info("setNotificationEnableSlot success");
    }).catch((err: BusinessError) => {
        console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`);
    });

notificationManager.isNotificationSlotEnabled

isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback<boolean>): void

Checks whether a notification slot type is enabled for the specified application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

System API: This is a system API.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
type SlotType Yes Notification slot type.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means that the notification slot type is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// isNotificationSlotEnabledCallback
let isNotificationSlotEnabledCallback = (err: BusinessError, data: boolean): void => {
    if (err) {
        console.error(`isNotificationSlotEnabled failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`isNotificationSlotEnabled success, data is ${JSON.stringify(data)}`);
    }
};

notificationManager.isNotificationSlotEnabled(
    { bundle: "ohos.samples.notification", },
    notificationManager.SlotType.SOCIAL_COMMUNICATION,
    isNotificationSlotEnabledCallback);

notificationManager.isNotificationSlotEnabled

isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise<boolean>

Checks whether a notification slot type is enabled for the specified application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
type SlotType Yes Notification slot type.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that the notification slot type is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// isNotificationSlotEnabled
notificationManager.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", },
    notificationManager.SlotType.SOCIAL_COMMUNICATION).then((data: boolean) => {
    console.info(`isNotificationSlotEnabled success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`isNotificationSlotEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setSyncNotificationEnabledWithoutApp(deprecated)

setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback<void>): void

Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses an asynchronous callback to return the result.

Since: 9

Deprecated since: 26.0.0

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
userId number Yes User ID.
enable boolean Yes Whether to enable the notification sync feature. The value true means to enable the feature, and false means the opposite.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Use the actual user ID when calling the API.
let userId: number = 100;
let enable: boolean = true;
let setSyncNotificationEnabledWithoutAppCallback = (err: BusinessError): void => {
    if (err) {
        console.error(`setSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info("setSyncNotificationEnabledWithoutApp success");
    }
}
notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotificationEnabledWithoutAppCallback);

notificationManager.setSyncNotificationEnabledWithoutApp(deprecated)

setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise<void>

Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result.

Since: 9

Deprecated since: 26.0.0

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
userId number Yes User ID.
enable boolean Yes Whether to enable the notification sync feature. The value true means to enable the feature, and false means the opposite.

Return value

Type Description
Promise<void> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Use the actual user ID when calling the API.
let userId: number = 100;
let enable: boolean = true;
notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => {
    console.info('setSyncNotificationEnabledWithoutApp success');
}).catch((err: BusinessError) => {
    console.error(`setSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getSyncNotificationEnabledWithoutApp(deprecated)

getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback<boolean>): void

Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses an asynchronous callback to return the result.

Since: 9

Deprecated since: 26.0.0

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
userId number Yes User ID.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means that the notification sync feature is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Use the actual user ID when calling the API.
let userId: number = 100;
let getSyncNotificationEnabledWithoutAppCallback = (err: BusinessError, data: boolean): void => {
    if (err) {
        console.error(`getSyncNotificationEnabledWithoutAppCallback failed, code is ${err.code}, message is ${err.message}`);
    } else {
        console.info(`getSyncNotificationEnabledWithoutAppCallback success, data: ${JSON.stringify(data)}`);
    }
}
notificationManager.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEnabledWithoutAppCallback);

notificationManager.getSyncNotificationEnabledWithoutApp(deprecated)

getSyncNotificationEnabledWithoutApp(userId: number): Promise<boolean>

Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result.

Since: 9

Deprecated since: 26.0.0

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
userId number Yes User ID.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that the notification sync feature is enabled, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Use the actual user ID when calling the API.
let userId: number = 100;
notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data: boolean) => {
  console.info(`getSyncNotificationEnabledWithoutApp, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.on10+

on(type: 'checkNotification', callback: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void

Subscribes to notification events. The notification service sends the notification information in the callback to the verification program. The verification program returns the verification result to determine whether to publish the notification, for example, controlling the publication frequency of marketing notifications.

Each SlotType in the system can have only one registrant.

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
type string Yes Event type. The value is fixed to 'checkNotification'.
callback (checkInfo: NotificationCheckInfo) => NotificationCheckResult Yes Pointer to the notification verification function.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let onCheckNotification = (info : notificationManager.NotificationCheckInfo): notificationManager.NotificationCheckResult => {
    console.info(`====>OnCheckNotification info: ${JSON.stringify(info)}`);
    if(info.notificationId == 1){
        let result: notificationManager.NotificationCheckResult =  { code: 1, message: "testMsg1"};
        return result;
    } else {
        let result: notificationManager.NotificationCheckResult =   { code: 0, message: "testMsg0"};
        return result;
    }
}
try{
    notificationManager.on("checkNotification", onCheckNotification);
} catch (err){
    console.error(`notificationManager.on failed, code is ${err.code}, message is ${err.message}`);
}

notificationManager.on11+

on(type: 'checkNotification', checkRequest: NotificationCheckRequest, callback: (checkInfo: NotificationCheckInfo) => Promise<NotificationCheckResult>): void

Subscribes to notification events. The notification service sends the notification information in the callback to the verification program. The verification program returns the verification result to determine whether to publish the notification, for example, controlling the publication frequency of marketing notifications. This API uses a promise to return the result.

Each SlotType in the system can have only one registrant.

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
type string Yes Event type. The value is fixed to 'checkNotification'.
checkRequest NotificationCheckRequest Yes Notification verification content.
callback (checkInfo: NotificationCheckInfo) => Promise<NotificationCheckResult> Yes Pointer to the notification verification function.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

try{
  notificationManager.on('checkNotification',{
    contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LIVE_VIEW,
    slotType: notificationManager.SlotType.LIVE_VIEW ,
    extraInfoKeys: ["event"],
  },
    async (checkInfo)=>{
      return { code: 1, message: "INVALID_PARAMETERS"};
  },);
} catch (err) {
  console.error(`notificationManager.on failed, code is ${err.code}, message is ${err.message}`);
}

notificationManager.off10+

off(type: 'checkNotification', callback?: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void

Unsubscribes from notification events.

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
type string Yes Event type. The value is fixed to 'checkNotification'.
callback (checkInfo: NotificationCheckInfo) => NotificationCheckResult No Pointer to the notification verification function.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.

Example

import { BusinessError } from '@kit.BasicServicesKit';

try{
    notificationManager.off("checkNotification");
} catch (err){
    console.error(`notificationManager.off failed, code is ${err.code}, message is ${err.message}`);
}

notificationManager.triggerSystemLiveView11+

triggerSystemLiveView(bundle: BundleOption, notificationId: number, buttonOptions: ButtonOptions): Promise<void>

Triggers a system live view notification. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
notificationId number Yes Notification ID.
buttonOptions ButtonOptions Yes Button information.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600007 The notification does not exist.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Bundle information
let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
// Notification ID
let notificationId = 1;
// Button information
let buttonOptions: notificationManager.ButtonOptions = {
    buttonName: "buttonName1",
}
notificationManager.triggerSystemLiveView(bundle, notificationId, buttonOptions).then(() => {
  console.info("triggerSystemLiveView success");
}).catch((err: BusinessError) => {
  console.error(`triggerSystemLiveView failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.subscribeSystemLiveView11+

subscribeSystemLiveView(subscriber: SystemLiveViewSubscriber): Promise<void>

Subscribes to the system live view notification. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

System API: This is a system API.

Parameters

Name Type Mandatory Description
subscriber SystemLiveViewSubscriber Yes Subscriber of the system live view notification.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let onResponseCallback = (id:number, option:notificationManager.ButtonOptions) => {
    console.info(`notificationId: ${id},onResponseCallback: ${JSON.stringify(option)}`);
}
let subscriber: notificationManager.SystemLiveViewSubscriber  = {
    onResponse: onResponseCallback,
};
notificationManager.subscribeSystemLiveView(subscriber).then(() => {
    console.info("subscribeSystemLiveView success");
}).catch((err: BusinessError) => {
    console.error(`subscribeSystemLiveView failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setDistributedEnabledByBundle12+

setDistributedEnabledByBundle(bundle: BundleOption, deviceType: string, enable: boolean): Promise<void>

Sets whether a specified application enables cross-device collaboration. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
deviceType string Yes Device type.
enable boolean Yes Whether a specified application enables cross-device collaboration. The value true indicates that the cross-device collaboration is enabled, and the value false indicates the opposite.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
    uid: 1
};
let enable: boolean = true;
let deviceType: string = "phone";
notificationManager.setDistributedEnabledByBundle(bundle, deviceType, enable).then(() => {
    console.info("setDistributedEnabledByBundle success");
}).catch((err: BusinessError) => {
    console.error(`setDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setDistributedEnableByBundles20+

setDistributedEnableByBundles(bundleEnableInfos: Array<DistributedBundleEnableInfo>, deviceType: string): Promise<void>

Sets whether applications enable cross-device collaboration. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundleEnableInfos Array<DistributedBundleEnableInfo> Yes Applications to set.
deviceType string Yes Device type.

Return value

Type Description
Promise<void> Promise that returns no result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle1: notificationManager.DistributedBundleEnableInfo = {
    bundleName: "bundleName1",
    uid: 1,
    enable: true
};
let bundle2: notificationManager.DistributedBundleEnableInfo = {
    bundleName: "bundleName2",
    uid: 2,
    enable: true
};
let bundles: Array<notificationManager.DistributedBundleEnableInfo> = [
    bundle1,bundle2
]

let deviceType: string = "liteWearable";
notificationManager.setDistributedEnableByBundles(bundles, deviceType).then(() => {
    console.info("setDistributedEnableByBundles success");
}).catch((err: BusinessError) => {
    console.error(`setDistributedEnableByBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isDistributedEnabledByBundle12+

isDistributedEnabledByBundle(bundle: BundleOption, deviceType: string): Promise<boolean>

Obtains whether a specified application enables cross-device collaboration. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
deviceType string Yes Device type.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true indicates that the cross-device collaboration is enabled, and the value false indicates the opposite.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
    uid: 1
};
let deviceType: string = "phone";
notificationManager.isDistributedEnabledByBundle(bundle, deviceType).then((data: boolean) => {
    console.info(`isDistributedEnabledByBundle success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`isDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setSmartReminderEnabled12+

setSmartReminderEnabled(deviceType: string, enable: boolean): Promise<void>

Sets a smart reminder for cross-device collaboration. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
deviceType string Yes Device type.
enable boolean Yes Indicates whether the specified application supports a smart reminder for cross-device collaboration (true: enabled; false: disabled).

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let deviceType: string = "phone";
let enable: boolean = true;
notificationManager.setSmartReminderEnabled(deviceType, enable).then(() => {
    console.info("setSmartReminderEnabled success");
}).catch((err: BusinessError) => {
    console.error(`setSmartReminderEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isSmartReminderEnabled12+

isSmartReminderEnabled(deviceType: string): Promise<boolean>

Obtains a smart reminder for cross-device collaboration. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
deviceType string Yes Device type.

Return value

Type Description
Promise<boolean> Promise used to return the result (true: enabled; false: disabled).

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600010 Distributed operation failed.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let deviceType: string = "phone";
notificationManager.isSmartReminderEnabled(deviceType).then((data: boolean) => {
    console.info(`isSmartReminderEnabled success, data:${data}`);
}).catch((err: BusinessError) => {
    console.error(`isSmartReminderEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setBadgeNumberByBundle12+

setBadgeNumberByBundle(bundle: BundleOption, badgeNumber: number): Promise<void>

Sets the badge count for other applications. This API uses a promise to return the result.

The current application must have a proxy relationship with another application, or the ohos.permission.NOTIFICATION_AGENT_CONTROLLER permission is granted to the current application.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
badgeNumber number Yes Notification badge number to set.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.
1600017 There is no corresponding agent relationship configuration.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: 'com.example.bundleName',
};
let badgeNumber: number = 10;

notificationManager.setBadgeNumberByBundle(bundle, badgeNumber).then(() => {
    console.info('setBadgeNumberByBundle success');
}).catch((err: BusinessError) => {
    console.error(`setBadgeNumberByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getSlotByBundle12+

getSlotByBundle(bundle: BundleOption, slotType: SlotType): Promise<NotificationSlot>

Obtains a notification slot of a specified application. This API uses a promise to return the result.

Before obtaining the notification slot, create a slot through addSlot.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
slotType SlotType Yes Notification slot type.

Return value

Type Description
Promise<NotificationSlot> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};

let slotType = notificationManager.SlotType.LIVE_VIEW;

notificationManager.getSlotByBundle(bundle, slotType).then((data: notificationManager.NotificationSlot) => {
    console.info(`getSlotByBundle success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getSlotByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.addDoNotDisturbProfile12+

addDoNotDisturbProfile(templates: Array<DoNotDisturbProfile>): Promise<void>

Adds the Do Not Disturb profile. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
templates Array<DoNotDisturbProfile> Yes Do Not Disturb profile.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let trustlist: Array<notificationManager.BundleOption> = [
  {
    bundle: 'com.example.bundleName',
    uid: 0
  },
  {
    bundle: 'com.example.bundleName1',
    uid: 1
  }
]
let templates: Array<notificationManager.DoNotDisturbProfile> = [
  {
    id: 3,
    name: 'working mode',
    trustlist: trustlist
  }
]

notificationManager.addDoNotDisturbProfile(templates).then(() => {
  console.info("addDoNotDisturbProfile success.");
}).catch((err: BusinessError) => {
  console.error(`addDoNotDisturbProfile failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.addDoNotDisturbProfile23+

addDoNotDisturbProfile(templates: Array<DoNotDisturbProfile>, userId: number): Promise<void>

Adds the Do Not Disturb profile for a specified user. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

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

System API: This is a system API.

Parameters

Name Type Mandatory Description
templates Array<DoNotDisturbProfile> Yes Do Not Disturb profile.
userId number Yes ID of the target user.

Return value

Type Description
Promise<void> Promise that returns no result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let userId : number = 100;
let trustlist: Array<notificationManager.BundleOption> = [
  {
    // Replace it as required.
    bundle: 'bundleName',
    uid: 0
  },
  {
    // Replace it as required.
    bundle: 'bundleName1',
    uid: 1
  }
]
let templates: Array<notificationManager.DoNotDisturbProfile> = [
  {
    id: 3,
    name: 'working mode',
    trustlist: trustlist
  }
]

notificationManager.addDoNotDisturbProfile(templates, userId).then(() => {
  console.info("addDoNotDisturbProfile success.");
}).catch((err: BusinessError) => {
  console.error(`addDoNotDisturbProfile failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.removeDoNotDisturbProfile12+

removeDoNotDisturbProfile(templates: Array<DoNotDisturbProfile>): Promise<void>

Deletes the Do Not Disturb profile. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
templates Array<DoNotDisturbProfile> Yes Do Not Disturb profile.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let templates: Array<notificationManager.DoNotDisturbProfile> = [
  {
    id: 3,
    name: 'working mode'
  }
]
notificationManager.removeDoNotDisturbProfile(templates).then(() => {
  console.info("removeDoNotDisturbProfile success.");
}).catch((err: BusinessError) => {
  console.error(`removeDoNotDisturbProfile failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.removeDoNotDisturbProfile23+

removeDoNotDisturbProfile(templates: Array<DoNotDisturbProfile>, userId: number): Promise<void>

Deletes the Do Not Disturb profile of a specified user. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

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

System API: This is a system API.

Parameters

Name Type Mandatory Description
templates Array<DoNotDisturbProfile> Yes Do Not Disturb profile.
userId number Yes ID of the target user.

Return value

Type Description
Promise<void> Promise that returns no result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let userId : number = 100;
let templates: Array<notificationManager.DoNotDisturbProfile> = [
  {
    id: 3,
    name: 'working mode'
  }
]
notificationManager.removeDoNotDisturbProfile(templates, userId).then(() => {
  console.info("removeDoNotDisturbProfile success.");
}).catch((err: BusinessError) => {
  console.error(`removeDoNotDisturbProfile failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setAdditionalConfig12+

setAdditionalConfig(key: string, value: string): Promise<number>

Sets the additional system configuration information of the notification. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
key string Yes Additional configuration key. Currently, only RING_TRUSTLIST_PKG is supported, indicating that the application supports custom ringtones.
value string Yes Additional configuration value. Example: [bundleName1,bundleName2].

Return value

Type Description
Promise<number> Promise used to return the result. 0 indicates successful; other values indicate failed.

Error codes

For details about the error codes, see Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.setAdditionalConfig('RING_TRUSTLIST_PKG','[bundleName1,bundleName2]').then((data: number) => {
  console.info(`setAdditionalConfig success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
  console.error(`setAdditionalConfig failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getDoNotDisturbProfile13+

getDoNotDisturbProfile(id: number): Promise<DoNotDisturbProfile>

Queries the Do Not Disturb profile. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
id number Yes ID of the Do Not Disturb profile.

Return value

Type Description
Promise<DoNotDisturbProfile> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600019 The do-not-disturb profile does not exist.

Example

import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.getDoNotDisturbProfile(1).then((data: notificationManager.DoNotDisturbProfile) => {
  console.info(`getDoNotDisturbProfile success: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
  console.error(`getDoNotDisturbProfile failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getDoNotDisturbProfile23+

getDoNotDisturbProfile(id: number, userId: number): Promise<DoNotDisturbProfile>

Queries the Do Not Disturb profile of a specified user. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables and TVs. If it is called on wearables and TVs, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

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

System API: This is a system API.

Parameters

Name Type Mandatory Description
id number Yes ID of the Do Not Disturb profile.
userId number Yes Target user.

Return value

Type Description
Promise<DoNotDisturbProfile> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600008 The user does not exist.
1600019 The do-not-disturb profile does not exist.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let id : number = 101;
let userId : number = 100;

notificationManager.getDoNotDisturbProfile(id, userId).then((data: notificationManager.DoNotDisturbProfile) => {
  console.info(`getDoNotDisturbProfile success: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
  console.error(`getDoNotDisturbProfile failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.disableNotificationFeature18+

disableNotificationFeature(disabled: boolean, bundleList: Array<string>): Promise<void>

Disables the application from publishing notifications by adding the application bundle name to the permission control list. This function can be disabled as required.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.MANAGE_EDM_POLICY

System API: This is a system API.

Parameters

Name Type Mandatory Description
disabled boolean Yes Whether to enable the permission control list for publishing notifications (true: enabled; false: disabled).
bundleList Array<string> Yes Application list under the permission control list. The bundle name is used to represent a specific application.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.
801 Capability not supported.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let disabled: boolean = true;
let bundleList: Array<string> = ["com.example.myapplication"];
try {
  notificationManager.disableNotificationFeature(disabled, bundleList).then(() => {
    hilog.info(0x0000, 'testTag', '%{public}s', `disableNotificationFeature success.`);
  }).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', '%{public}s', `disableNotificationFeature failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (err) {
  hilog.error(0x0000, 'testTag', '%{public}s', `testTag failed, code is ${err.code}, message is ${err.message}`);
}

notificationManager.disableNotificationFeature20+

disableNotificationFeature(disabled: boolean, bundleList: Array<string>, userId: number): Promise<void>

Disables the application from publishing notifications by adding the application bundle name to the permission control list. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Device behavior differences: This API can be properly called on devices other than wearables. If it is called on wearables, error code 801 is returned.

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER or ohos.permission.MANAGE_EDM_POLICY

System API: This is a system API.

Parameters

Name Type Mandatory Description
disabled boolean Yes Whether to enable the notification permission control list. The value true indicates that the notification permission control list is enabled; false indicates the opposite.
bundleList Array<string> Yes Bundles under the permission control list. The bundle name is used to represent a specific application.
userId number Yes User ID.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission verification failed. The application does not have the permission required to call the API.
202 Permission verification failed. A non-system application calls a system API.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let disabled: boolean = true;
let bundleList: Array<string> = ["com.example.myapplication"];
let userId: number = 1;
try {
  notificationManager.disableNotificationFeature(disabled, bundleList, userId).then(() => {
    hilog.info(0x0000, 'testTag', '%{public}s', `disableNotificationFeature success.`);
  }).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', '%{public}s', `disableNotificationFeature failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (err) {
  hilog.error(0x0000, 'testTag', '%{public}s', `testTag failed, code is ${err.code}, message is ${err.message}`);
}

notificationManager.setTargetDeviceStatus18+

setTargetDeviceStatus(deviceType: string, status: number): Promise<void>

Sets the status of a device after it is successfully connected. Device status determines the notification mode of the current device when a notification is published.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
deviceType string Yes Device type. Currently, only headset, liteWearable, wearable, glasses, and current are supported.
status number Yes Device status.
- Bit 0: whether the device is in use. The value 0 indicates that the device is available; 1 indicates that the device is in use.
- Bit 1: whether the device user is the owner. The value 0 indicates that the user is not the owner; 1 indicates the opposite.
- Bit 2: whether the device is in the Do Not Disturb mode. The value 0 indicates that the device is not in the Do Not Disturb mode; 1 indicates the opposite.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.setTargetDeviceStatus("current", 1).then(() => {
  console.info(`Succeeded in setting target device status.`);
}).catch((err: BusinessError) => {
  console.error(`Failed to set target device status. Code is ${err.code}, message is ${err.message}`);
});

notificationManager.setDistributedEnabledBySlot18+

setDistributedEnabledBySlot(slot: SlotType, deviceType: string, enabled: boolean): Promise<void>

Sets whether notifications of a specified slot can be sent to devices of a specified type through cross-device collaboration. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
slot SlotType Yes Types of the notification slot.
deviceType string Yes Device type.
Since API version 18, the following device types are supported:
- headset: wearable audio device
- liteWearable: lite wearable
- wearable: wearable
Since API version 20, the following device types are supported:
- headset: wearable audio device
- liteWearable: lite wearable
- wearable: wearable
- current: current device
- 2in1: PC
- tablet: tablet
enabled boolean Yes Whether to enable cross-device collaboration for notifications. The value true means to enable cross-device collaboration, and false means the opposite.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let slot: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
let deviceType: string = 'wearable';
let enabled: boolean = true;

notificationManager.setDistributedEnabledBySlot(slot, deviceType, enabled).then(() => {
    hilog.info(0x0000, 'testTag', '%{public}s', `setDistributedEnabledBySlot success.`);
}).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', '%{public}s', `setDistributedEnabledBySlot failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isDistributedEnabledBySlot18+

isDistributedEnabledBySlot(slot: SlotType, deviceType: string): Promise<boolean>

Queries whether notifications of a specified slot can be sent to devices of a specified type. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
slot SlotType Yes Types of the notification slot.
deviceType string Yes Device type.
Since API version 18, the following device types are supported:
- headset: wearable audio device
- liteWearable: lite wearable
- wearable: wearable
Since API version 20, the following device types are supported:
- headset: wearable audio device
- liteWearable: lite wearable
- wearable: wearable
- current: current device
- 2in1: PC
- tablet: tablet

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that cross-device collaboration is supported, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let slot: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
let deviceType: string = 'wearable';

notificationManager.isDistributedEnabledBySlot(slot, deviceType).then((data: boolean) => {
    hilog.info(0x0000, 'testTag', '%{public}s', `isDistributedEnabledBySlot success.`);
}).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', '%{public}s', `isDistributedEnabledBySlot failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setSilentReminderEnabled20+

setSilentReminderEnabled(bundle: BundleOption, enabled: boolean): Promise<void>

Sets the enabling status of the silent reminder. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
enabled boolean Yes Whether to enable the silent reminder. The value true means to enable the silent reminder, and false means the opposite.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName",
};
notificationManager.setSilentReminderEnabled(bundle, true).then(() => {
    hilog.info(0x0000, 'testTag', '%{public}s', `setSilentReminderEnabled success.`);
}).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', '%{public}s', `setSilentReminderEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isSilentReminderEnabled20+

isSilentReminderEnabled(bundle: BundleOption): Promise<SwitchState>

Checks whether the silent reminder is enabled. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.

Return value

Type Description
Promise<SwitchState> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName1",
};
notificationManager.isSilentReminderEnabled(bundle).then((data: notificationManager.SwitchState) => {
    hilog.info(0x0000, 'testTag', '%{public}s', `isSilentReminderEnabled success, switchState:  ${JSON.stringify(data)}.`);
}).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', '%{public}s', `isSilentReminderEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isDistributedEnabled20+

isDistributedEnabled(deviceType: string): Promise<boolean>

Checks whether a device enables cross-device notification. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
deviceType string Yes Device type. The options are as follows:
- headset: wearable audio device
- liteWearable: lite wearable
- wearable: wearable
- current: current device
- 2in1: PC
- tablet: tablet

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true indicates that the cross-device notification is enabled, and the value false indicates the opposite.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.

Example

import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
  }

  onForeground(): void {
    try {
      let deviceType: string = "wearable";
      notificationManager.isDistributedEnabled(deviceType).then((data: boolean) => {
        console.info('isDistributedEnabled succeeded, result = ' + data);
      }).catch((err: BusinessError) => {
        console.error(`isDistributedEnabled failed. Code is ${err.code}, message is ${err.message}`);
      });
    } catch (err) {
      console.error(`isDistributedEnabled failed. Code is ${err.code}, message is ${err.message}`);
    }
  }
}

notificationManager.setDistributedEnabled20+

setDistributedEnabled(enable: boolean, deviceType: string): Promise<void>

Sets whether the device of a specified type enables cross-device notification. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
enable boolean Yes Whether the device of a specified type enables cross-device notification. The value true indicates that the cross-device notification is enabled, and the value false indicates the opposite.
deviceType string Yes Device type. The options are as follows:
- headset: wearable audio device
- liteWearable: lite wearable
- wearable: wearable
- current: current device
- 2in1: PC
- tablet: tablet

Return value

Type Description
Promise<void> Promise that returns no result.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.

Example

import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
  }

  onForeground(): void {
    try {
      let isEnable: boolean = true;
      let deviceType: string = "wearable";
      notificationManager.setDistributedEnabled(isEnable, deviceType).then(() => {
        console.info('setDistributedEnabled succeeded.');
      }).catch((err: BusinessError) => {
        console.error(`setDistributedEnabled failed. Code is ${err.code}, message is ${err.message}`);
      });
    } catch (err) {
      console.error(`setDistributedEnabled failed. Code is ${err.code}, message is ${err.message}`);
    }
  }
}

notificationManager.getDistributedDeviceList20+

getDistributedDeviceList(): Promise<Array<string>>

Obtains the device types that enable cross-device notification. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Return value

Type Description
Promise<Array<string>> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.

Example

import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
  }

  onForeground(): void {
    try {
      notificationManager.getDistributedDeviceList().then((data: Array<string>) => {
        console.info('getDistributedDeviceList succeeded, result = ' + data);
      }).catch((err: BusinessError) => {
        console.error(`getDistributedDeviceList failed. Code is ${err.code}, message is ${err.message}`);
      });
    } catch (err) {
      console.error(`getDistributedDeviceList failed. Code is ${err.code}, message is ${err.message}`);
    }
  }
}

notificationManager.setRingtoneInfoByBundle21+

setRingtoneInfoByBundle(bundle: BundleOption, ringtoneInfo: RingtoneInfo): Promise<void>

Sets the custom ringtone information for an application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
ringtoneInfo RingtoneInfo Yes Custom ringtone information.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.
1600022 The specified bundle is invalid.

Example

import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
  }

  onForeground(): void {
    try {
      let bundle: notificationManager.BundleOption = {
        bundle: "bundleName",
      };
      let ringtoneInfo: notificationManager.RingtoneInfo = {
        ringtoneType: notificationManager.RingtoneType.RINGTONE_TYPE_SYSTEM,
        ringtoneTitle: "ringtoneName",
        ringtoneFileName: "ringtonePath",
        ringtoneUri: "ringtoneUri",
      }
      notificationManager.setRingtoneInfoByBundle(bundle, ringtoneInfo).then(() => {
        console.info(`setRingtoneInfoByBundle bundle: ${JSON.stringify(bundle)}', ringtoneInfoJSON: ' ${JSON.stringify(ringtoneInfo)}`);
      }).catch((err: BusinessError) => {
         console.error(`setRingtoneInfoByBundle failed, code is ${err.code}, message is ${err.message}`);
      });
    } catch (err) {
      console.error(`setRingtoneInfoByBundle failed, code is ${err.code}, message is ${err.message}`);
    }
  }
}

notificationManager.getRingtoneInfoByBundle21+

getRingtoneInfoByBundle(bundle: BundleOption): Promise<RingtoneInfo>

Obtains the custom ringtone information of an application. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.

Return value

Type Description
Promise<RingtoneInfo> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.
1600022 The specified bundle is invalid.
1600024 The specified bundle has no custom ringtone information.

Example

import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
  }

  onForeground(): void {
    try {
      let bundle: notificationManager.BundleOption = {
        bundle: "bundleName",
      };
      notificationManager.getRingtoneInfoByBundle(bundle)
        .then((ringtoneInfo: notificationManager.RingtoneInfo) => {
          console.info(`getRingtoneInfoByBundle success: ${JSON.stringify(ringtoneInfo)}`);
        }).catch((err: BusinessError) => {
        console.error(`getRingtoneInfoByBundle failed, code is ${err.code}, message is ${err.message}`);
      });
    } catch (err) {
      console.error(`getRingtoneInfoByBundle failed, code is ${err.code}, message is ${err.message}`);
    }
  }
}

notificationManager.setBadgeDisplayStatusByBundles21+

setBadgeDisplayStatusByBundles(badges: Map<BundleOption, boolean>): Promise<void>

Batch sets whether to display badges for specified applications. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
badges Map<BundleOption, boolean> Yes List containing bundle names and badge display statuses.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let badges = new Map<notificationManager.BundleOption, boolean>();
let bundle: notificationManager.BundleOption = {
    bundle: 'bundleName',
};
badges.set(bundle, true);

notificationManager.setBadgeDisplayStatusByBundles(badges).then(() => {
    console.info('SetBadgeDisplayStatusByBundles success.');
}).catch((err: BusinessError) => {
    console.error(`SetBadgeDisplayStatusByBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getBadgeDisplayStatusByBundles21+

getBadgeDisplayStatusByBundles(bundles:Array<BundleOption>): Promise<Map<BundleOption, boolean>>

Batch obtains the display statuses of application badges. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundles Array<BundleOption> Yes Bundles whose badge display statuses are to be obtained.

Return value

Type Description
Promise<Map<BundleOption, boolean>> Promise used to return the bundles and the badge display statuses obtained.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundles: Array<notificationManager.BundleOption> = [
    {
        bundle: 'bundleName',
    },
    {
        bundle: 'bundleName1',
    }
];
notificationManager.getBadgeDisplayStatusByBundles(bundles).then((data: Map<notificationManager.BundleOption, boolean>) => {
    data.forEach((value, key) => {
        console.info(`Bundle is ${key.bundle}, uid is ${key.uid}, badge status is ${value}.`);
    });
}).catch((err: BusinessError) => {
    console.error(`GetBadgeDisplayStatusByBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setReminderInfoByBundles21+

setReminderInfoByBundles(reminderInfos: Array<NotificationReminderInfo>): Promise<void>

Batch sets reminders for specified applications. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
reminderInfos Array<NotificationReminderInfo> Yes Reminders to be set.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundle: notificationManager.BundleOption = {
    bundle: "bundleName",
};
let reminderInfos: Array<notificationManager.NotificationReminderInfo> = [
    {
        bundle: bundle,
        reminderFlags: 59,
        silentReminderEnabled: false
    }
];
notificationManager.setReminderInfoByBundles(reminderInfos).then(() => {
    console.info('SetReminderInfoByBundles success.');
}).catch((err: BusinessError) => {
    console.error(`SetReminderInfoByBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getReminderInfoByBundles21+

getReminderInfoByBundles(bundles: Array<BundleOption>): Promise<Array<NotificationReminderInfo>>

Batch obtains reminders of specified applications. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundles Array<BundleOption> Yes Bundles whose reminders are to be obtained.

Return value

Type Description
Promise<Array<NotificationReminderInfo>> Promise used to return the application reminders obtained.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundles: Array<notificationManager.BundleOption> = [
    {
        bundle: 'bundleName',
    },
    {
        bundle: 'bundleName1',
    }
];
notificationManager.getReminderInfoByBundles(bundles).then((data: Array<notificationManager.NotificationReminderInfo>) => {
    console.info(`Reminder data is ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`GetReminderInfoByBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isPriorityEnabled23+

isPriorityEnabled(): Promise<boolean>

Checks whether the priority notification is enabled.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Return value

Type Description
Promise<boolean> Promise used to return the result.
- true: The priority notification is enabled.
- false: The priority notification is disabled.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

notificationManager.isPriorityEnabled().then((result : boolean) => {
    hilog.info(0x0000, 'testTag', `isPriorityEnabled result is ${result}`);
}).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', `isPriorityEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setPriorityEnabled23+

setPriorityEnabled(enable: boolean): Promise<void>

Sets the enabling status of the priority notification.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
enable boolean Yes Whether to enable the priority notification.
- true: The priority notification is enabled.
- false: The priority notification is disabled.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

notificationManager.setPriorityEnabled(false).then(() => {
    hilog.info(0x0000, 'testTag', `setPriorityEnabled success`);
}).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', `setPriorityEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isPriorityEnabledByBundle23+

isPriorityEnabledByBundle(bundle: BundleOption): Promise<PriorityEnableStatus>

Checks whether the priority notification for a specified application is enabled.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.

Return value

Type Description
Promise<PriorityEnableStatus> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const bundleOption : notificationManager.BundleOption = { bundle: 'bundleName', uid: 0 };
notificationManager.isPriorityEnabledByBundle(bundleOption).then((result : notificationManager.PriorityEnableStatus) => {
  hilog.info(0x0000, 'testTag', `isPriorityEnabledByBundle result is ${result}`);
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `isPriorityEnabledByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setPriorityEnabledByBundle23+

setPriorityEnabledByBundle(bundle: BundleOption, enableStatus: PriorityEnableStatus): Promise<void>

Sets the enabling status of the priority notification for an application.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
enableStatus PriorityEnableStatus Yes Whether the priority notification for an application is enabled.
- DISABLE: The priority notification is disabled.
- ENABLE_BY_INTELLIGENT: The priority notification can be enabled through intelligent recognition, user keyword matching, or application rule matching.
- ENABLE: The priority notification is enabled for all applications.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const bundleOption : notificationManager.BundleOption = { bundle: 'bundleName', uid: 0 };
notificationManager.setPriorityEnabledByBundle(bundleOption, notificationManager.PriorityEnableStatus.ENABLE).then(() => {
  hilog.info(0x0000, 'testTag', `setPriorityEnabledByBundle success`);
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `setPriorityEnabledByBundle failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getBundlePriorityConfig23+

getBundlePriorityConfig(bundle: BundleOption): Promise<string>

Obtains the priority configuration of an application.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.

Return value

Type Description
Promise<string> Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const bundleOption : notificationManager.BundleOption = { bundle: 'bundleName', uid: 0 };
notificationManager.getBundlePriorityConfig(bundleOption).then((value: string) => {
  hilog.info(0x0000, 'testTag', `getBundlePriorityConfig value is ${value}`);
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `getBundlePriorityConfig failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setBundlePriorityConfig23+

setBundlePriorityConfig(bundle: BundleOption, value: string): Promise<void>

Sets the priority configuration of an application.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundle BundleOption Yes Bundle information of the application.
value string Yes Priority configuration of an application.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.
1600001 Internal error.
1600003 Failed to connect to the service.
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const bundleOption : notificationManager.BundleOption = { bundle: 'bundleName', uid: 0 };
notificationManager.setBundlePriorityConfig(bundleOption, 'keyword\nkeyword1').then(() => {
  hilog.info(0x0000, 'testTag', `setBundlePriorityConfig success`);
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `setBundlePriorityConfig failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.isPriorityIntelligentEnabled23+

isPriorityIntelligentEnabled(): Promise<boolean>

Obtains whether the intelligent priority notification service is enabled. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

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

Return value

Type Description
Promise<boolean> Promise that contains the enabling status of the intelligent priority notification service.
- true: The intelligent priority notification service is enabled.
- false: The intelligent priority notification service is disabled.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.
1600012 No memory space

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

notificationManager.isPriorityIntelligentEnabled().then((result: boolean) => {
  hilog.info(0x0000, 'testTag', `isPriorityIntelligentEnabled result: ${result}`);
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `isPriorityIntelligentEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setPriorityIntelligentEnabled23+

setPriorityIntelligentEnabled(enable: boolean): Promise<void>

Sets the enabling status of the intelligent priority notification service. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

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

Parameters

Name Type Mandatory Description
enable boolean Yes Enabling status of the intelligent priority notification service.
- true: The intelligent priority notification service is enabled.
- false: The intelligent priority notification service is disabled.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.
1600012 No memory space

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

notificationManager.setPriorityIntelligentEnabled(false).then(() => {
  hilog.info(0x0000, 'testTag', `setPriorityIntelligentEnabled success`);
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `setPriorityIntelligentEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getPriorityEnabledByBundles23+

getPriorityEnabledByBundles(bundles: Array<BundleOption>): Promise<Map<BundleOption, boolean>>

Obtains whether priority notifications are enabled for applications in batches. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

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

Parameters

Name Type Mandatory Description
bundles Array<BundleOption> Yes Array of application bundles.

Return value

Type Description
Promise<Map<BundleOption, boolean>> Promise used to return the key-value pair set of the application notification priority enabling status.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.
1600012 No memory space
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const bundleOption : notificationManager.BundleOption = { bundle: 'bundleName', uid: 1000 };
let bundles: Array<notificationManager.BundleOption> = new Array(bundleOption);
notificationManager.getPriorityEnabledByBundles(bundles).then((switches: Map<notificationManager.BundleOption, boolean>) => {
  switches.forEach((value, key) => {
    hilog.info(0x0000, 'testTag', `getPriorityEnabledByBundles switches: ${key.bundle} ${key.uid}, ${value}`);
  })
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `getPriorityEnabledByBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setPriorityEnabledByBundles23+

setPriorityEnabledByBundles(switches: Map<BundleOption, boolean>): Promise<void>

Sets whether priority notifications are enabled for applications in batches. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

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

Parameters

Name Type Mandatory Description
switches Map<BundleOption, boolean> Yes Key-value pair set of the application notification priority enabling status.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.
1600012 No memory space
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const bundleOption : notificationManager.BundleOption = { bundle: 'bundleName', uid: 1000 };
let switches: Map<notificationManager.BundleOption, boolean> = new Map([[bundleOption, false]]);
notificationManager.setPriorityEnabledByBundles(switches).then(() => {
  hilog.info(0x0000, 'testTag', `setPriorityEnabledByBundles success`);
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `setPriorityEnabledByBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getPriorityStrategyByBundles23+

getPriorityStrategyByBundles(bundles: Array<BundleOption>): Promise<Map<BundleOption, number>>;

Obtains the application priority notification strategies in batches. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

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

Parameters

Name Type Mandatory Description
bundles Array<BundleOption> Yes Array of application bundles.

Return value

Type Description
Promise<Map<BundleOption, number>> Promise used to return the key-value pair set of the application notification priority strategies.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.
1600012 No memory space
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const bundleOption : notificationManager.BundleOption = { bundle: 'bundleName', uid: 1000 };
let bundles: Array<notificationManager.BundleOption> = new Array(bundleOption);
notificationManager.getPriorityStrategyByBundles(bundles).then((strategies: Map<notificationManager.BundleOption, number>) => {
  strategies.forEach((value, key) => {
    hilog.info(0x0000, 'testTag', `getPriorityStrategyByBundles strategies: ${key.bundle} ${key.uid}, ${value}`);
  })
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `getPriorityStrategyByBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.setPriorityStrategyByBundles23+

setPriorityStrategyByBundles(strategies: Map<BundleOption, number>): Promise<void>

Sets the application priority notification strategies in batches. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

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

Parameters

Name Type Mandatory Description
strategies Map<BundleOption, number> Yes Key-value pair set of the application notification priority strategies. This parameter is obtained by performing the bitwise OR operation with the enumeration of PriorityStrategyStatus.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes, Notification Error Codes, and Bundle Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.
1600012 No memory space
17700001 The specified bundle name was not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const bundleOption : notificationManager.BundleOption = { bundle: 'bundleName', uid: 1000 };
let strategies: Map<notificationManager.BundleOption, number> = new Map([[bundleOption, notificationManager.PriorityStrategyStatus.STATUS_APPLICATION_DEFINED]]);
notificationManager.setPriorityStrategyByBundles(strategies).then(() => {
  hilog.info(0x0000, 'testTag', `setPriorityStrategyByBundles success`);
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `setPriorityStrategyByBundles failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.onBadgeNumberQuery22+

onBadgeNumberQuery(callback: (bundle: BundleOption) => Promise<number>): void

Registers a callback for querying the number of application badges.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
callback (bundle: BundleOption) => Promise<number> Yes Number of target application badges.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

try{
    notificationManager.onBadgeNumberQuery(
        async (bundleOption: notificationManager.BundleOption) => {
            return 1;
        }
    );
} catch (err) {
    console.error(`OnBadgeNumberQuery failed, code is ${err.code}, message is ${err.message}`);
}

notificationManager.offBadgeNumberQuery22+

offBadgeNumberQuery(): void

Unregisters the callback for querying the number of application badges.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.

Example

try{
    notificationManager.offBadgeNumberQuery();
} catch (err) {
    console.error(`OffBadgeNumberQuery failed, code is ${err.code}, message is ${err.message}`);
}

notificationManager.setGeofenceEnabled23+

setGeofenceEnabled(enabled: boolean): Promise<void>

Sets the enabling state of geofencing. This API uses a promise to return the result.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

System API: This is a system API.

Parameters

Name Type Mandatory Description
enabled boolean Yes Whether geofencing is enabled. The value true indicates that geofencing is enabled, and the value false indicates the opposite.

Return value

Type Description
Promise<void> Promise that returns no result.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600002 Marshalling or unmarshalling error.
1600003 Failed to connect to the service.
1600012 No memory space.

Example

import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';

notificationManager.setGeofenceEnabled(true).then(() => {
  hilog.info(0x0000, 'testTag', '%{public}s', "setGeofenceEnabled success");
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', '%{public}s',`setGeofenceEnabled failed, code is ${err.code}, message is ${err.message}`);
});

notificationManager.getNotificationStatisticsByBundle

getNotificationStatisticsByBundle(bundles: BundleOption[]): Promise<BundleNotificationStatistics[]>

Obtains notification statistics of a specified list of applications in batches. This API uses a promise to return the result.

Since: 26.0.0

System API: This is a system API.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

Device behavior differences: This API can be properly called only on phones, PCs, and 2-in-1 devices. On other devices, it returns the error code 801.

Parameters

Name Type Mandatory Description
bundles BundleOption[] Yes List of application bundle information.

Return value

Type Description
Promise<BundleNotificationStatistics[]> Promise used to return the notification statistics of a specified list of applications.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
801 Capability not supported.
1600001 Internal error.
1600003 Failed to connect to the service.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundles: notificationManager.BundleOption[] = [
  { bundle:"com.example.test01" },
  { bundle:"com.example.test02" }
];
notificationManager.getNotificationStatisticsByBundle(bundles).then(
  (data: notificationManager.BundleNotificationStatistics[]) => {
  console.info(`getNotificationStatisticsByBundle success, data is ${JSON.stringify(data)}`)
}).catch((err: BusinessError):void => {
  console.error(`getNotificationStatisticsByBundle err: ${JSON.stringify(err)}`)
});

notificationManager.snoozeNotification

snoozeNotification(hashCode: string, delayTime: number): Promise<void>

Snoozes a notification. The notification will be reminded again after the specified time. Each setting will trigger only one reminder, and the reminder mode will be the same as that of the notification.
The notification will be deleted after the setting.

Since: 26.0.0

System API: This is a system API.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER

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

Parameters

Name Type Mandatory Description
hashCode string Yes Unique ID of the notification to be snoozed.
delayTime number Yes Interval for the snoozed notification.
Unit: second.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Notification Error Codes.

ID Error Message
201 Permission denied.
202 Not system application to call the interface.
1600001 Internal error.
1600003 Failed to connect to the service.
1600007 The notification does not exist.
1600028 This notification is not supported.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Replace it with the unique ID of the notification to be snoozed.
let hashCode: string = "hashCode";
let delayTime: number = 60;
notificationManager.snoozeNotification(hashCode, delayTime).then(() => {
  console.info("snoozeNotification success.")
}).catch((err: BusinessError):void => {
  console.error(`snoozeNotification failed, code is ${err.code}, message is ${err.message}`);
});

DoNotDisturbDate

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Type Read-Only Optional Description
type DoNotDisturbType No No DND time type.
begin Date No No DND start time.
end Date No No DND end time.

DoNotDisturbType

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Value Description
TYPE_NONE 0 Non-DND.
TYPE_ONCE 1 One-shot DND at the specified time segment (only considering the hour and minute).
TYPE_DAILY 2 Daily DND at the specified time segment (only considering the hour and minute).
TYPE_CLEARLY 3 DND at the specified time segment (with the hour, day, and month specified).

DeviceRemindType

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Value Description
IDLE_DONOT_REMIND 0 The device is not in use. No notification is required.
IDLE_REMIND 1 The device is not in use.
ACTIVE_DONOT_REMIND 2 The device is in use. No notification is required.
ACTIVE_REMIND 3 The device is in use.

SourceType

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Value Description
TYPE_NORMAL 0 Normal notification.
TYPE_CONTINUOUS 1 Continuous notification.
TYPE_TIMER 2 Timed notification.

NotificationCheckInfo10+

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Name Type Read-Only Optional Description
bundleName string No No Bundle name.
notificationId number No No Notification ID.
label11+ string No Yes Notification label.
contentType ContentType No No Notification type.
creatorUserId11+ number No No User ID of the notification.
slotType11+ SlotType No No Notification slot type.
extraInfos11+ Record<string, Object> No Yes Extra information about the live view.

NotificationCheckResult10+

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Name Type Read-Only Optional Description
code number No No Result code.
0: display.
1: no display.
message string No No Result.

ButtonOptions11+

Provides the button information of the notification.

System capability: SystemCapability.Notification.Notification

Required permissions: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER

System API: This is a system API.

Name Type Read-Only Optional Description
buttonName string No No Button name.

SystemLiveViewSubscriber11+

Subscriber of the system live view notification.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Type Read-Only Optional Description
onResponse (notificationId: number, buttonOptions: ButtonOptions) => void No Yes Callback when the button is touched.

SlotType

System capability: SystemCapability.Notification.Notification

Name Value Description
EMERGENCY_INFORMATION12+ 10 Emergency event. System API: This is a system API.

NotificationControlFlagStatus12+

Each bit can control the notification mode. When the bitwise OR operation is performed on notificationControlFlags and the enumerated values in the following table, the notification mode is disabled.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Value Description
NOTIFICATION_STATUS_CLOSE_SOUND 1<<0 Disables the sound notification function.
NOTIFICATION_STATUS_CLOSE_LOCKSCREEN 1<<1 Disables the screen lock notification function.
NOTIFICATION_STATUS_CLOSE_BANNER 1<<2 Disables the banner notification function.
NOTIFICATION_STATUS_CLOSE_LIGHT_SCREEN 1<<3 Disables the screen-on notification function.
NOTIFICATION_STATUS_CLOSE_VIBRATION 1<<4 Disables the vibration notification function.
NOTIFICATION_STATUS_CLOSE_STATUSBAR_ICON 1<<5 Disables the icon notification function in the status bar.

DoNotDisturbProfile12+

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Type Read-Only Optional Description
id number No No ID of the Do Not Disturb profile.
name string No No Name of the Do Not Disturb profile.
trustlist Array<BundleOption> No Yes Trustlist in Do Not Disturb profile.

NotificationLiveViewContent11+

type NotificationLiveViewContent = _NotificationLiveViewContent

Describes the common live view.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Type Description
_NotificationLiveViewContent Common live view.

SwitchState20+

Describes the switch state of notifications.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Value Description
USER_MODIFIED_OFF 0 Disabled state set by the user.
USER_MODIFIED_ON 1 Enabled state set by the user.
SYSTEM_DEFAULT_OFF 2 Initial disabled state before user settings.
SYSTEM_DEFAULT_ON 3 Initial enabled state before user settings.

DistributedBundleEnableInfo20+

Describes the bundle information of an application that enables cross-device collaboration.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Type Read-Only Optional Description
bundleName string No No Bundle name.
uid number No No UID of the application.
enable boolean No Yes Whether the application enables cross-device collaboration. The value true indicates that the cross-device collaboration is enabled, and the value false indicates the opposite.

RingtoneType21+

Enumerates the custom ringtone types.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Value Description
RINGTONE_TYPE_SYSTEM 0 System ringtone.
RINGTONE_TYPE_LOCAL 1 Local ringtone.
RINGTONE_TYPE_ONLINE 2 Online ringtone.
RINGTONE_TYPE_NONE 3 Non-custom ringtone.

RingtoneInfo21+

Describes the custom ringtone information.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Type Read-Only Optional Description
ringtoneType RingtoneType No No Type of the ringtone.
ringtoneTitle string No Yes Title of the ringtone.
ringtoneFileName string No Yes File name of the ringtone.
ringtoneUri string No Yes URI of the ringtone.

NotificationReminderInfo21+

Describes the information about the application reminder.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Type Read-Only Optional Description
bundle BundleOption No No Bundle information of the application.
reminderFlags number No No Reminder flag.
silentReminderEnabled boolean No No Whether the silent reminder is enabled. The value true indicates that the silent reminder is enabled, and the value false indicates the opposite.

BundleNotificationStatistics

Describes the notification statistics of a specified application.

Since: 26.0.0

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Type Read-Only Optional Description
bundle BundleOption No No Bundle information of the application.
lastTime number No No Last time when the application sent a notification. Data format: timestamp, in ms.
recentCount number No No Total number of notifications released by the application in the last seven days.

PriorityNotificationType23+

Describes the priority type of a notification.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Value Description
PAYMENT_DUE "PAYMENT_DUE" Payment and repayment.
TRANSACTION_ALERT "TRANSACTION_ALERT" Account balance reminder.
EXPRESS_PROGRESS "EXPRESS_PROGRESS" Express progress.
MISS_CALL "MISS_CALL" Missed call.
TRAVEL_ALERT "TRAVEL_ALERT" Abnormal traveling.
ACCOUNT_ALERT "ACCOUNT_ALERT" Account security.
APPOINTMENT_REMINDER "APPOINTMENT_REMINDER" Appointment reminder.
TRAFFIC_NOTICE "TRAFFIC_NOTICE" Traffic violation.
KEY_PROGRESS "KEY_PROGRESS" Key progress.
PUBLIC_EVENT "PUBLIC_EVENT" Important common event.
IOT_WARNING "IOT_WARNING" IoT warning.
CUSTOM_KEYWORD "CUSTOM_KEYWORD" Custom keyword.

PriorityEnableStatus23+

Describes the enabling status of the priority notification for an application.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Name Value Description
DISABLE 0 The priority notification is disabled.
ENABLE_BY_INTELLIGENT 1 The priority notification is enabled by intelligent recognition.
ENABLE 2 The priority notification is enabled for all applications.

NotificationIconButton23+

type NotificationIconButton = _NotificationIconButton

System notification button.

System capability: SystemCapability.Notification.Notification

System API: This is a system API.

Type Description
_NotificationIconButton System notification button.

TriggerType 23+

type TriggerType = _TriggerType

Enumerates the trigger types.

System capability: SystemCapability.Notification.Notification

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

System API: This is a system API.

Type Description
_TriggerType Condition trigger type.

Trigger 23+

type Trigger = _Trigger

Defines the details for triggering a geofence.

System capability: SystemCapability.Notification.Notification

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

System API: This is a system API.

Type Description
_Trigger Trigger condition.

Geofence 23+

type Geofence = _Geofence

Defines the configuration of a geofence.

System capability: SystemCapability.Notification.Notification

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

System API: This is a system API.

Type Description
_Geofence Geofence configuration information.

CoordinateSystemType 23+

type CoordinateSystemType = _CoordinateSystemType

Enumerates the coordinate systems of a geofence.

System capability: SystemCapability.Notification.Notification

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

System API: This is a system API.

Type Description
_CoordinateSystemType Type of the geofence coordinate system.

MonitorEvent 23+

type MonitorEvent = _MonitorEvent

Enumerates the event types of monitoring a geofence.

System capability: SystemCapability.Notification.Notification

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

System API: This is a system API.

Type Description
_MonitorEvent Event type of monitoring a geofence.

PriorityStrategyStatus23+

Describes the application notification strategy.

System capability: SystemCapability.Notification.Notification

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

System API: This is a system API.

Name Value Description
STATUS_SYSTEM_DEFAULT 1<<0 Default priority strategy.
STATUS_SYSTEM_RULE 1<<1 Only system rule.
STATUS_INTELLIGENT 1<<2 Only intelligent recognition.
STATUS_USER_DEFINED 1<<3 Only user-defined.
STATUS_APPLICATION_DEFINED 1<<4 Only application-defined.
STATUS_ALL_PRIORITY 1<<5 All.

GroupInfo

type GroupInfo = _GroupInfo

Defines the custom group notification information.

Since: 26.0.0

System capability: SystemCapability.Notification.Notification

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

System API: This is a system API.

Type Description
_GroupInfo Type of the custom group notification information.