1e41f4b71Sopenharmony_ci# @ohos.notificationManager (NotificationManager模块) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci本模块提供通知管理的能力,包括发布、取消发布通知,创建、获取、移除通知渠道,获取通知的使能状态、角标使能状态,获取通知的相关信息等。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## 导入模块 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { notificationManager } from '@kit.NotificationKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## notificationManager.publish 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_cipublish(request: NotificationRequest, callback: AsyncCallback\<void\>): void 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci发布通知。使用callback异步回调。 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci如果新发布通知与已发布通知的ID相同,且label相同,则新通知将取代原有通知。 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**参数:** 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 28e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | ---- | ------------------------------------------- | 29e41f4b71Sopenharmony_ci| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是 | 用于设置要发布通知的内容和相关配置信息。 | 30e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 发布通知的回调方法。 | 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**错误码:** 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 37e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | 38e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 39e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 40e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 41e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 42e41f4b71Sopenharmony_ci| 1600004 | Notification disabled. | 43e41f4b71Sopenharmony_ci| 1600005 | Notification slot disabled. | 44e41f4b71Sopenharmony_ci| 1600007 | The notification does not exist. | 45e41f4b71Sopenharmony_ci| 1600009 | The notification sending frequency reaches the upper limit. | 46e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 47e41f4b71Sopenharmony_ci| 1600014 | No permission. | 48e41f4b71Sopenharmony_ci| 1600015 | The current notification status does not support duplicate configurations. | 49e41f4b71Sopenharmony_ci| 1600016 | The notification version for this update is too low. | 50e41f4b71Sopenharmony_ci| 2300007 | Network unreachable. | 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**示例:** 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci```ts 55e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci// publish回调 58e41f4b71Sopenharmony_cilet publishCallback = (err: BusinessError): void => { 59e41f4b71Sopenharmony_ci if (err) { 60e41f4b71Sopenharmony_ci console.error(`publish failed, code is ${err.code}, message is ${err.message}`); 61e41f4b71Sopenharmony_ci } else { 62e41f4b71Sopenharmony_ci console.info("publish success"); 63e41f4b71Sopenharmony_ci } 64e41f4b71Sopenharmony_ci} 65e41f4b71Sopenharmony_ci// 通知Request对象 66e41f4b71Sopenharmony_cilet notificationRequest: notificationManager.NotificationRequest = { 67e41f4b71Sopenharmony_ci id: 1, 68e41f4b71Sopenharmony_ci content: { 69e41f4b71Sopenharmony_ci notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 70e41f4b71Sopenharmony_ci normal: { 71e41f4b71Sopenharmony_ci title: "test_title", 72e41f4b71Sopenharmony_ci text: "test_text", 73e41f4b71Sopenharmony_ci additionalText: "test_additionalText" 74e41f4b71Sopenharmony_ci } 75e41f4b71Sopenharmony_ci } 76e41f4b71Sopenharmony_ci}; 77e41f4b71Sopenharmony_cinotificationManager.publish(notificationRequest, publishCallback); 78e41f4b71Sopenharmony_ci``` 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci## notificationManager.publish 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_cipublish(request: NotificationRequest): Promise\<void\> 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci发布通知。使用Promise异步回调。 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci如果新发布通知与已发布通知的ID相同,且label相同,则新通知将取代原有通知。 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**参数:** 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 93e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | ---- | ------------------------------------------- | 94e41f4b71Sopenharmony_ci| request | [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) | 是 | 用于设置要发布通知的内容和相关配置信息。 | 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci**返回值:** 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci| 类型 | 说明 | 99e41f4b71Sopenharmony_ci| ------- |--| 100e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**错误码:** 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 107e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | 108e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 109e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 110e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 111e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 112e41f4b71Sopenharmony_ci| 1600004 | Notification disabled. | 113e41f4b71Sopenharmony_ci| 1600005 | Notification slot disabled. | 114e41f4b71Sopenharmony_ci| 1600007 | The notification does not exist. | 115e41f4b71Sopenharmony_ci| 1600009 | The notification sending frequency reaches the upper limit. | 116e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 117e41f4b71Sopenharmony_ci| 1600014 | No permission. | 118e41f4b71Sopenharmony_ci| 1600015 | The current notification status does not support duplicate configurations. | 119e41f4b71Sopenharmony_ci| 1600016 | The notification version for this update is too low. | 120e41f4b71Sopenharmony_ci| 2300007 | Network unreachable. | 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci**示例:** 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci```ts 125e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci// 通知Request对象 128e41f4b71Sopenharmony_cilet notificationRequest: notificationManager.NotificationRequest = { 129e41f4b71Sopenharmony_ci id: 1, 130e41f4b71Sopenharmony_ci content: { 131e41f4b71Sopenharmony_ci notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, 132e41f4b71Sopenharmony_ci normal: { 133e41f4b71Sopenharmony_ci title: "test_title", 134e41f4b71Sopenharmony_ci text: "test_text", 135e41f4b71Sopenharmony_ci additionalText: "test_additionalText" 136e41f4b71Sopenharmony_ci } 137e41f4b71Sopenharmony_ci } 138e41f4b71Sopenharmony_ci}; 139e41f4b71Sopenharmony_cinotificationManager.publish(notificationRequest).then(() => { 140e41f4b71Sopenharmony_ci console.info("publish success"); 141e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 142e41f4b71Sopenharmony_ci console.error(`publish fail: ${JSON.stringify(err)}`); 143e41f4b71Sopenharmony_ci}); 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci``` 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci## notificationManager.cancel 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_cicancel(id: number, label: string, callback: AsyncCallback\<void\>): void 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci通过通知ID和通知标签取消已发布的通知。使用callback异步回调。 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**参数:** 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 158e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | -------------------- | 159e41f4b71Sopenharmony_ci| id | number | 是 | 通知ID。 | 160e41f4b71Sopenharmony_ci| label | string | 是 | 通知标签。 | 161e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 表示被指定通知的回调方法。 | 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**错误码:** 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 168e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 169e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 170e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 171e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 172e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 173e41f4b71Sopenharmony_ci| 1600007 | The notification does not exist. | 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**示例:** 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci```ts 178e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci// cancel回调 181e41f4b71Sopenharmony_cilet cancelCallback = (err: BusinessError): void => { 182e41f4b71Sopenharmony_ci if (err) { 183e41f4b71Sopenharmony_ci console.error(`cancel failed, code is ${err.code}, message is ${err.message}`); 184e41f4b71Sopenharmony_ci } else { 185e41f4b71Sopenharmony_ci console.info("cancel success"); 186e41f4b71Sopenharmony_ci } 187e41f4b71Sopenharmony_ci} 188e41f4b71Sopenharmony_cinotificationManager.cancel(0, "label", cancelCallback); 189e41f4b71Sopenharmony_ci``` 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci## notificationManager.cancel 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_cicancel(id: number, label?: string): Promise\<void\> 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci通过通知ID和通知标签取消已发布的通知,若label为空表示取消与指定通知ID相匹配的已发布通知。使用Promise异步回调。 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci**参数:** 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 202e41f4b71Sopenharmony_ci| ----- | ------ | ---- | -------- | 203e41f4b71Sopenharmony_ci| id | number | 是 | 通知ID。 | 204e41f4b71Sopenharmony_ci| label | string | 否 | 通知标签,默认为空。 | 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci**返回值:** 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci| 类型 | 说明 | 209e41f4b71Sopenharmony_ci| ------- |-----------| 210e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci**错误码:** 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 217e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 218e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 219e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 220e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 221e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 222e41f4b71Sopenharmony_ci| 1600007 | The notification does not exist. | 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci**示例:** 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci```ts 227e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_cinotificationManager.cancel(0).then(() => { 230e41f4b71Sopenharmony_ci console.info("cancel success"); 231e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 232e41f4b71Sopenharmony_ci console.error(`cancel fail: ${JSON.stringify(err)}`); 233e41f4b71Sopenharmony_ci}); 234e41f4b71Sopenharmony_ci``` 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci## notificationManager.cancel 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_cicancel(id: number, callback: AsyncCallback\<void\>): void 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci取消与指定通知ID相匹配的已发布通知。使用callback异步回调。 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**参数:** 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 247e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | -------------------- | 248e41f4b71Sopenharmony_ci| id | number | 是 | 通知ID。 | 249e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 表示被指定通知的回调方法。 | 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci**错误码:** 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 256e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 257e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 258e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 259e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 260e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 261e41f4b71Sopenharmony_ci| 1600007 | The notification does not exist. | 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci**示例:** 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci```ts 266e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci// cancel回调 269e41f4b71Sopenharmony_cilet cancelCallback = (err: BusinessError): void => { 270e41f4b71Sopenharmony_ci if (err) { 271e41f4b71Sopenharmony_ci console.error(`cancel failed, code is ${err.code}, message is ${err.message}`); 272e41f4b71Sopenharmony_ci } else { 273e41f4b71Sopenharmony_ci console.info("cancel success"); 274e41f4b71Sopenharmony_ci } 275e41f4b71Sopenharmony_ci} 276e41f4b71Sopenharmony_cinotificationManager.cancel(0, cancelCallback); 277e41f4b71Sopenharmony_ci``` 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci## notificationManager.cancelAll 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_cicancelAll(callback: AsyncCallback\<void\>): void 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci取消当前应用所有已发布的通知。使用callback异步回调。 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci**参数:** 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 290e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | -------------------- | 291e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 表示被指定通知的回调方法。 | 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci**错误码:** 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 298e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 299e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 300e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 301e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 302e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci**示例:** 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci```ts 307e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci// cancel回调 310e41f4b71Sopenharmony_cilet cancelAllCallback = (err: BusinessError): void => { 311e41f4b71Sopenharmony_ci if (err) { 312e41f4b71Sopenharmony_ci console.error(`cancelAll failed, code is ${err.code}, message is ${err.message}`); 313e41f4b71Sopenharmony_ci } else { 314e41f4b71Sopenharmony_ci console.info("cancelAll success"); 315e41f4b71Sopenharmony_ci } 316e41f4b71Sopenharmony_ci} 317e41f4b71Sopenharmony_cinotificationManager.cancelAll(cancelAllCallback); 318e41f4b71Sopenharmony_ci``` 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci## notificationManager.cancelAll 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_cicancelAll(): Promise\<void\> 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci取消当前应用所有已发布的通知。使用Promise异步回调。 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci**返回值:** 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci| 类型 | 说明 | 331e41f4b71Sopenharmony_ci| ------- |-----------| 332e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci**错误码:** 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 339e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 340e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 341e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 342e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 343e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci**示例:** 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci```ts 348e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_cinotificationManager.cancelAll().then(() => { 351e41f4b71Sopenharmony_ci console.info("cancelAll success"); 352e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 353e41f4b71Sopenharmony_ci console.error(`cancelAll fail: ${JSON.stringify(err)}`); 354e41f4b71Sopenharmony_ci}); 355e41f4b71Sopenharmony_ci``` 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci## notificationManager.addSlot 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ciaddSlot(type: SlotType, callback: AsyncCallback\<void\>): void 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci创建指定类型的通知渠道。使用callback异步回调。 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**参数:** 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 368e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ---------------------- | 369e41f4b71Sopenharmony_ci| type | [SlotType](#slottype) | 是 | 要创建的通知渠道的类型。 | 370e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 表示被指定通道的回调方法。 | 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci**错误码:** 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 377e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 378e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 379e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 380e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 381e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 382e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci**示例:** 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci```ts 387e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci// addslot回调 390e41f4b71Sopenharmony_cilet addSlotCallBack = (err: BusinessError): void => { 391e41f4b71Sopenharmony_ci if (err) { 392e41f4b71Sopenharmony_ci console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`); 393e41f4b71Sopenharmony_ci } else { 394e41f4b71Sopenharmony_ci console.info("addSlot success"); 395e41f4b71Sopenharmony_ci } 396e41f4b71Sopenharmony_ci} 397e41f4b71Sopenharmony_cinotificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack); 398e41f4b71Sopenharmony_ci``` 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci## notificationManager.addSlot 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ciaddSlot(type: SlotType): Promise\<void\> 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci创建指定类型的通知渠道。使用Promise异步回调。 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci**参数:** 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 411e41f4b71Sopenharmony_ci| ---- | -------- | ---- | ---------------------- | 412e41f4b71Sopenharmony_ci| type | [SlotType](#slottype) | 是 | 要创建的通知渠道的类型。 | 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci**返回值:** 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci| 类型 | 说明 | 417e41f4b71Sopenharmony_ci| ------- |-----------| 418e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci**错误码:** 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 425e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 426e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 427e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 428e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 429e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 430e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci**示例:** 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci```ts 435e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_cinotificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION).then(() => { 438e41f4b71Sopenharmony_ci console.info("addSlot success"); 439e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 440e41f4b71Sopenharmony_ci console.error(`addSlot fail: ${JSON.stringify(err)}`); 441e41f4b71Sopenharmony_ci}); 442e41f4b71Sopenharmony_ci``` 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci## notificationManager.getSlot 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_cigetSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci获取一个指定类型的通知渠道。使用callback异步回调。 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci**参数:** 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 455e41f4b71Sopenharmony_ci| -------- | --------------------------------- | ---- | ----------------------------------------------------------- | 456e41f4b71Sopenharmony_ci| slotType | [SlotType](#slottype) | 是 | 通知渠道类型,例如社交通信、服务提醒、内容咨询等类型。 | 457e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | 是 | 表示被指定通道的回调方法。 | 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci**错误码:** 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 464e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 465e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 466e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 467e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 468e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci**示例:** 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ci```ts 473e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci// getSlot回调 476e41f4b71Sopenharmony_cilet getSlotCallback = (err: BusinessError, data: notificationManager.NotificationSlot): void => { 477e41f4b71Sopenharmony_ci if (err) { 478e41f4b71Sopenharmony_ci console.error(`getSlot failed, code is ${err.code}, message is ${err.message}`); 479e41f4b71Sopenharmony_ci } else { 480e41f4b71Sopenharmony_ci console.info(`getSlot success, data is ${JSON.stringify(data)}`); 481e41f4b71Sopenharmony_ci } 482e41f4b71Sopenharmony_ci} 483e41f4b71Sopenharmony_cilet slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 484e41f4b71Sopenharmony_cinotificationManager.getSlot(slotType, getSlotCallback); 485e41f4b71Sopenharmony_ci``` 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci## notificationManager.getSlot 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_cigetSlot(slotType: SlotType): Promise\<NotificationSlot\> 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci获取一个指定类型的通知渠道。使用Promise异步回调。 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ci**参数:** 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 498e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ----------------------------------------------------------- | 499e41f4b71Sopenharmony_ci| slotType | [SlotType](#slottype) | 是 | 通知渠道类型,例如社交通信、服务提醒、内容咨询等类型。 | 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci**返回值:** 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci| 类型 | 说明 | 504e41f4b71Sopenharmony_ci| ----------------------------------------------------------- | ------------------------------------------------------------ | 505e41f4b71Sopenharmony_ci| Promise\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\> | 以Promise形式返回获取一个通知渠道。 | 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci**错误码:** 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 512e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 513e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 514e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 515e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 516e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci**示例:** 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci```ts 521e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_cilet slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 524e41f4b71Sopenharmony_cinotificationManager.getSlot(slotType).then((data: notificationManager.NotificationSlot) => { 525e41f4b71Sopenharmony_ci console.info("getSlot success, data: " + JSON.stringify(data)); 526e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 527e41f4b71Sopenharmony_ci console.error(`getSlot fail: ${JSON.stringify(err)}`); 528e41f4b71Sopenharmony_ci}); 529e41f4b71Sopenharmony_ci``` 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ci## notificationManager.getSlots 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_cigetSlots(callback: AsyncCallback\<Array\<NotificationSlot>>): void 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci获取此应用程序的所有通知渠道。使用callback异步回调。 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci**参数:** 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 542e41f4b71Sopenharmony_ci| -------- | --------------------------------- | ---- | -------------------- | 543e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | 是 | 以callback形式返回获取此应用程序的所有通知渠道的结果。 | 544e41f4b71Sopenharmony_ci 545e41f4b71Sopenharmony_ci**错误码:** 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 548e41f4b71Sopenharmony_ci 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 551e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 552e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 553e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 554e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 555e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ci**示例:** 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci```ts 560e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 561e41f4b71Sopenharmony_ci 562e41f4b71Sopenharmony_ci// getSlots回调 563e41f4b71Sopenharmony_cilet getSlotsCallback = (err: BusinessError, data: Array<notificationManager.NotificationSlot>): void => { 564e41f4b71Sopenharmony_ci if (err) { 565e41f4b71Sopenharmony_ci console.error(`getSlots failed, code is ${err.code}, message is ${err.message}`); 566e41f4b71Sopenharmony_ci } else { 567e41f4b71Sopenharmony_ci console.info(`getSlots success, data is ${JSON.stringify(data)}`); 568e41f4b71Sopenharmony_ci } 569e41f4b71Sopenharmony_ci} 570e41f4b71Sopenharmony_cinotificationManager.getSlots(getSlotsCallback); 571e41f4b71Sopenharmony_ci``` 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_ci## notificationManager.getSlots 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_cigetSlots(): Promise\<Array\<NotificationSlot>> 576e41f4b71Sopenharmony_ci 577e41f4b71Sopenharmony_ci获取此应用程序的所有通知渠道。使用Promise异步回调。 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci**返回值:** 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci| 类型 | 说明 | 584e41f4b71Sopenharmony_ci| ----------------------------------------------------------- | ------------------------------------------------------------ | 585e41f4b71Sopenharmony_ci| Promise\<Array\<[NotificationSlot](js-apis-inner-notification-notificationSlot.md)\>\> | 以Promise形式返回获取此应用程序的所有通知渠道的结果。 | 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ci**错误码:** 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 592e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 593e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 594e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 595e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 596e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci**示例:** 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci```ts 601e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_cinotificationManager.getSlots().then((data: Array<notificationManager.NotificationSlot>) => { 604e41f4b71Sopenharmony_ci console.info("getSlots success, data: " + JSON.stringify(data)); 605e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 606e41f4b71Sopenharmony_ci console.error(`getSlots fail: ${JSON.stringify(err)}`); 607e41f4b71Sopenharmony_ci}); 608e41f4b71Sopenharmony_ci``` 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci## notificationManager.removeSlot 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ciremoveSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci删除此应用程序指定类型的通知渠道。使用callback异步回调。 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci**参数:** 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 621e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ----------------------------------------------------------- | 622e41f4b71Sopenharmony_ci| slotType | [SlotType](#slottype) | 是 | 通知渠道类型,例如社交通信、服务提醒、内容咨询等类型。 | 623e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 表示被指定通道的回调方法。 | 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ci**错误码:** 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 630e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 631e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 632e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 633e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 634e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci**示例:** 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci```ts 639e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ci// removeSlot回调 642e41f4b71Sopenharmony_cilet removeSlotCallback = (err: BusinessError): void => { 643e41f4b71Sopenharmony_ci if (err) { 644e41f4b71Sopenharmony_ci console.error(`removeSlot failed, code is ${err.code}, message is ${err.message}`); 645e41f4b71Sopenharmony_ci } else { 646e41f4b71Sopenharmony_ci console.info("removeSlot success"); 647e41f4b71Sopenharmony_ci } 648e41f4b71Sopenharmony_ci} 649e41f4b71Sopenharmony_cilet slotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 650e41f4b71Sopenharmony_cinotificationManager.removeSlot(slotType, removeSlotCallback); 651e41f4b71Sopenharmony_ci``` 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ci## notificationManager.removeSlot 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ciremoveSlot(slotType: SlotType): Promise\<void\> 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci删除此应用程序指定类型的通知渠道。使用Promise异步回调。 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_ci**参数:** 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 664e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ----------------------------------------------------------- | 665e41f4b71Sopenharmony_ci| slotType | [SlotType](#slottype) | 是 | 通知渠道类型,例如社交通信、服务提醒、内容咨询等类型。 | 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ci**返回值:** 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ci| 类型 | 说明 | 670e41f4b71Sopenharmony_ci|---------|-----------| 671e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci**错误码:** 674e41f4b71Sopenharmony_ci 675e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 676e41f4b71Sopenharmony_ci 677e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 678e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 679e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 680e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 681e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 682e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_ci**示例:** 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci```ts 687e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_cilet slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; 690e41f4b71Sopenharmony_cinotificationManager.removeSlot(slotType).then(() => { 691e41f4b71Sopenharmony_ci console.info("removeSlot success"); 692e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 693e41f4b71Sopenharmony_ci console.error(`removeSlot fail: ${JSON.stringify(err)}`); 694e41f4b71Sopenharmony_ci}); 695e41f4b71Sopenharmony_ci``` 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ci## notificationManager.removeAllSlots 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ciremoveAllSlots(callback: AsyncCallback\<void\>): void 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci删除此应用程序所有通知渠道。使用callback异步回调。 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ci**参数:** 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 708e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | -------------------- | 709e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 表示被指定通道的回调方法。 | 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_ci**错误码:** 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 716e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 717e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 718e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 719e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 720e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 721e41f4b71Sopenharmony_ci 722e41f4b71Sopenharmony_ci**示例:** 723e41f4b71Sopenharmony_ci 724e41f4b71Sopenharmony_ci```ts 725e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_cilet removeAllSlotsCallback = (err: BusinessError): void => { 728e41f4b71Sopenharmony_ci if (err) { 729e41f4b71Sopenharmony_ci console.error(`removeAllSlots failed, code is ${err.code}, message is ${err.message}`); 730e41f4b71Sopenharmony_ci } else { 731e41f4b71Sopenharmony_ci console.info("removeAllSlots success"); 732e41f4b71Sopenharmony_ci } 733e41f4b71Sopenharmony_ci} 734e41f4b71Sopenharmony_cinotificationManager.removeAllSlots(removeAllSlotsCallback); 735e41f4b71Sopenharmony_ci``` 736e41f4b71Sopenharmony_ci 737e41f4b71Sopenharmony_ci## notificationManager.removeAllSlots 738e41f4b71Sopenharmony_ci 739e41f4b71Sopenharmony_ciremoveAllSlots(): Promise\<void\> 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_ci删除此应用程序所有通知渠道。使用Promise异步回调。 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci**返回值:** 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci| 类型 | 说明 | 748e41f4b71Sopenharmony_ci|---------|-----------| 749e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci**错误码:** 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 756e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 757e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 758e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 759e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 760e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 761e41f4b71Sopenharmony_ci 762e41f4b71Sopenharmony_ci**示例:** 763e41f4b71Sopenharmony_ci 764e41f4b71Sopenharmony_ci```ts 765e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_cinotificationManager.removeAllSlots().then(() => { 768e41f4b71Sopenharmony_ci console.info("removeAllSlots success"); 769e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 770e41f4b71Sopenharmony_ci console.error(`removeAllSlots fail: ${JSON.stringify(err)}`); 771e41f4b71Sopenharmony_ci}); 772e41f4b71Sopenharmony_ci``` 773e41f4b71Sopenharmony_ci 774e41f4b71Sopenharmony_ci## notificationManager.isNotificationEnabled<sup>11+</sup> 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ciisNotificationEnabled(callback: AsyncCallback\<boolean\>): void 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci获取通知使能状态。使用callback异步回调。 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci**参数:** 783e41f4b71Sopenharmony_ci 784e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 785e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ------------------------ | 786e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean\> | 是 | 获取通知使能状态回调函数(true:使能,false:禁止)。 | 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ci**错误码:** 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 791e41f4b71Sopenharmony_ci 792e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 793e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 794e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 795e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 796e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 797e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 798e41f4b71Sopenharmony_ci| 1600008 | The user does not exist. | 799e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name was not found. | 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_ci**示例:** 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_ci```ts 804e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 805e41f4b71Sopenharmony_ci 806e41f4b71Sopenharmony_cilet isNotificationEnabledCallback = (err: BusinessError, data: boolean): void => { 807e41f4b71Sopenharmony_ci if (err) { 808e41f4b71Sopenharmony_ci console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`); 809e41f4b71Sopenharmony_ci } else { 810e41f4b71Sopenharmony_ci console.info(`isNotificationEnabled success, data is ${JSON.stringify(data)}`); 811e41f4b71Sopenharmony_ci } 812e41f4b71Sopenharmony_ci} 813e41f4b71Sopenharmony_ci 814e41f4b71Sopenharmony_cinotificationManager.isNotificationEnabled(isNotificationEnabledCallback); 815e41f4b71Sopenharmony_ci``` 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci## notificationManager.isNotificationEnabled<sup>11+</sup> 818e41f4b71Sopenharmony_ci 819e41f4b71Sopenharmony_ciisNotificationEnabled(): Promise\<boolean\> 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci获取通知使能状态。使用Promise异步回调。 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ci**返回值:** 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci| 类型 | 说明 | 828e41f4b71Sopenharmony_ci| ----------------------------------------------------------- | ------------------------------------------------------------ | 829e41f4b71Sopenharmony_ci| Promise\<boolean\> | 以Promise形式返回获取通知使能状态的结果(true:使能,false:禁止)。 | 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci**错误码:** 832e41f4b71Sopenharmony_ci 833e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 836e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 837e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 838e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 839e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 840e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 841e41f4b71Sopenharmony_ci| 1600008 | The user does not exist. | 842e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name was not found. | 843e41f4b71Sopenharmony_ci 844e41f4b71Sopenharmony_ci**示例:** 845e41f4b71Sopenharmony_ci 846e41f4b71Sopenharmony_ci```ts 847e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 848e41f4b71Sopenharmony_ci 849e41f4b71Sopenharmony_cinotificationManager.isNotificationEnabled().then((data: boolean) => { 850e41f4b71Sopenharmony_ci console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); 851e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 852e41f4b71Sopenharmony_ci console.error(`isNotificationEnabled fail: ${JSON.stringify(err)}`); 853e41f4b71Sopenharmony_ci}); 854e41f4b71Sopenharmony_ci``` 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_ci## notificationManager.isNotificationEnabledSync<sup>12+</sup> 857e41f4b71Sopenharmony_ci 858e41f4b71Sopenharmony_ciisNotificationEnabledSync(): boolean 859e41f4b71Sopenharmony_ci 860e41f4b71Sopenharmony_ci同步获取通知使能状态。 861e41f4b71Sopenharmony_ci 862e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 863e41f4b71Sopenharmony_ci 864e41f4b71Sopenharmony_ci**返回值:** 865e41f4b71Sopenharmony_ci 866e41f4b71Sopenharmony_ci| 类型 | 说明 | 867e41f4b71Sopenharmony_ci| ----------------------------------------------------------- |--------------------------------------------------------- | 868e41f4b71Sopenharmony_ci| boolean | 返回获取通知使能状态的结果。返回true,表示通知使能状态为开;返回false,表示通知使能状态为关。 | 869e41f4b71Sopenharmony_ci 870e41f4b71Sopenharmony_ci**错误码:** 871e41f4b71Sopenharmony_ci 872e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通知错误码](./errorcode-notification.md)。 873e41f4b71Sopenharmony_ci 874e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 875e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 876e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 877e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 878e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 879e41f4b71Sopenharmony_ci 880e41f4b71Sopenharmony_ci**示例:** 881e41f4b71Sopenharmony_ci 882e41f4b71Sopenharmony_ci```ts 883e41f4b71Sopenharmony_cilet enabled = notificationManager.isNotificationEnabledSync(); 884e41f4b71Sopenharmony_ciconsole.info(`isNotificationEnabledSync success, data is : ${JSON.stringify(enabled)}`); 885e41f4b71Sopenharmony_ci``` 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci## notificationManager.setBadgeNumber<sup>10+</sup> 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_cisetBadgeNumber(badgeNumber: number): Promise\<void\> 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci设定角标个数,在应用的桌面图标上呈现。使用Promise异步回调。 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci当角标设定个数取值0时,表示清除角标。取值大于99时,通知角标将显示99+。 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 896e41f4b71Sopenharmony_ci 897e41f4b71Sopenharmony_ci**参数:** 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 900e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ---------- | 901e41f4b71Sopenharmony_ci| badgeNumber | number | 是 | 角标个数。 | 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ci**返回值:** 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci| 类型 | 说明 | 906e41f4b71Sopenharmony_ci|---------|-----------| 907e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 908e41f4b71Sopenharmony_ci 909e41f4b71Sopenharmony_ci**错误码:** 910e41f4b71Sopenharmony_ci 911e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 912e41f4b71Sopenharmony_ci 913e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 914e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 915e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 916e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 917e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 918e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 919e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_ci**示例:** 922e41f4b71Sopenharmony_ci 923e41f4b71Sopenharmony_ci```ts 924e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 925e41f4b71Sopenharmony_ci 926e41f4b71Sopenharmony_cilet badgeNumber: number = 10; 927e41f4b71Sopenharmony_cinotificationManager.setBadgeNumber(badgeNumber).then(() => { 928e41f4b71Sopenharmony_ci console.info("setBadgeNumber success"); 929e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 930e41f4b71Sopenharmony_ci console.error(`setBadgeNumber fail: ${JSON.stringify(err)}`); 931e41f4b71Sopenharmony_ci}); 932e41f4b71Sopenharmony_ci``` 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci## notificationManager.setBadgeNumber<sup>10+</sup> 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_cisetBadgeNumber(badgeNumber: number, callback: AsyncCallback\<void\>): void 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ci设定角标个数,在应用的桌面图标上呈现。使用callback异步回调。 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci当角标设定个数取值0时,表示清除角标。取值大于99时,通知角标将显示99+。 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci**参数:** 945e41f4b71Sopenharmony_ci 946e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 947e41f4b71Sopenharmony_ci| ----------- | --------------------- | ---- | ------------------ | 948e41f4b71Sopenharmony_ci| badgeNumber | number | 是 | 角标个数。 | 949e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 设定角标回调函数。 | 950e41f4b71Sopenharmony_ci 951e41f4b71Sopenharmony_ci**错误码:** 952e41f4b71Sopenharmony_ci 953e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 954e41f4b71Sopenharmony_ci 955e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 956e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 957e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 958e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 959e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 960e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 961e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 962e41f4b71Sopenharmony_ci 963e41f4b71Sopenharmony_ci**示例:** 964e41f4b71Sopenharmony_ci 965e41f4b71Sopenharmony_ci```ts 966e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 967e41f4b71Sopenharmony_ci 968e41f4b71Sopenharmony_cilet setBadgeNumberCallback = (err: BusinessError): void => { 969e41f4b71Sopenharmony_ci if (err) { 970e41f4b71Sopenharmony_ci console.error(`setBadgeNumber failed code is ${err.code}, message is ${err.message}`); 971e41f4b71Sopenharmony_ci } else { 972e41f4b71Sopenharmony_ci console.info("setBadgeNumber success"); 973e41f4b71Sopenharmony_ci } 974e41f4b71Sopenharmony_ci} 975e41f4b71Sopenharmony_cilet badgeNumber: number = 10; 976e41f4b71Sopenharmony_cinotificationManager.setBadgeNumber(badgeNumber, setBadgeNumberCallback); 977e41f4b71Sopenharmony_ci``` 978e41f4b71Sopenharmony_ci 979e41f4b71Sopenharmony_ci## notificationManager.getActiveNotificationCount 980e41f4b71Sopenharmony_ci 981e41f4b71Sopenharmony_cigetActiveNotificationCount(callback: AsyncCallback\<number\>): void 982e41f4b71Sopenharmony_ci 983e41f4b71Sopenharmony_ci获取当前应用未删除的通知数。使用callback异步回调。 984e41f4b71Sopenharmony_ci 985e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 986e41f4b71Sopenharmony_ci 987e41f4b71Sopenharmony_ci**参数:** 988e41f4b71Sopenharmony_ci 989e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 990e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ---------------------- | 991e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number\> | 是 | 获取未删除通知数回调函数。 | 992e41f4b71Sopenharmony_ci 993e41f4b71Sopenharmony_ci**错误码:** 994e41f4b71Sopenharmony_ci 995e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 996e41f4b71Sopenharmony_ci 997e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 998e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 999e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1000e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1001e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1002e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1003e41f4b71Sopenharmony_ci 1004e41f4b71Sopenharmony_ci**示例:** 1005e41f4b71Sopenharmony_ci 1006e41f4b71Sopenharmony_ci```ts 1007e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_cilet getActiveNotificationCountCallback = (err: BusinessError, data: number): void => { 1010e41f4b71Sopenharmony_ci if (err) { 1011e41f4b71Sopenharmony_ci console.error(`getActiveNotificationCount failed, code is ${err.code}, message is ${err.message}`); 1012e41f4b71Sopenharmony_ci } else { 1013e41f4b71Sopenharmony_ci console.info(`getActiveNotificationCount success, data is ${JSON.stringify(data)}`); 1014e41f4b71Sopenharmony_ci } 1015e41f4b71Sopenharmony_ci} 1016e41f4b71Sopenharmony_ci 1017e41f4b71Sopenharmony_cinotificationManager.getActiveNotificationCount(getActiveNotificationCountCallback); 1018e41f4b71Sopenharmony_ci``` 1019e41f4b71Sopenharmony_ci 1020e41f4b71Sopenharmony_ci## notificationManager.getActiveNotificationCount 1021e41f4b71Sopenharmony_ci 1022e41f4b71Sopenharmony_cigetActiveNotificationCount(): Promise\<number\> 1023e41f4b71Sopenharmony_ci 1024e41f4b71Sopenharmony_ci获取当前应用未删除的通知数。使用Promise异步回调。 1025e41f4b71Sopenharmony_ci 1026e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1027e41f4b71Sopenharmony_ci 1028e41f4b71Sopenharmony_ci**返回值:** 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_ci| 类型 | 说明 | 1031e41f4b71Sopenharmony_ci| ----------------- | ------------------------------------------- | 1032e41f4b71Sopenharmony_ci| Promise\<number\> | 以Promise形式返回获取当前应用未删除通知数。 | 1033e41f4b71Sopenharmony_ci 1034e41f4b71Sopenharmony_ci**错误码:** 1035e41f4b71Sopenharmony_ci 1036e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1037e41f4b71Sopenharmony_ci 1038e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1039e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1040e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1041e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1042e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1043e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci**示例:** 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_ci```ts 1048e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1049e41f4b71Sopenharmony_ci 1050e41f4b71Sopenharmony_cinotificationManager.getActiveNotificationCount().then((data: number) => { 1051e41f4b71Sopenharmony_ci console.info("getActiveNotificationCount success, data: " + JSON.stringify(data)); 1052e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1053e41f4b71Sopenharmony_ci console.error(`getActiveNotificationCount fail: ${JSON.stringify(err)}`); 1054e41f4b71Sopenharmony_ci}); 1055e41f4b71Sopenharmony_ci``` 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ci## notificationManager.getActiveNotifications 1058e41f4b71Sopenharmony_ci 1059e41f4b71Sopenharmony_cigetActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>): void 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci获取当前应用未删除的通知列表。使用callback异步回调。 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1064e41f4b71Sopenharmony_ci 1065e41f4b71Sopenharmony_ci**参数:** 1066e41f4b71Sopenharmony_ci 1067e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1068e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 1069e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)>> | 是 | 获取当前应用通知列表回调函数。 | 1070e41f4b71Sopenharmony_ci 1071e41f4b71Sopenharmony_ci**错误码:** 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1076e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1077e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1078e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1079e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1080e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1081e41f4b71Sopenharmony_ci 1082e41f4b71Sopenharmony_ci**示例:** 1083e41f4b71Sopenharmony_ci 1084e41f4b71Sopenharmony_ci```ts 1085e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1086e41f4b71Sopenharmony_ci 1087e41f4b71Sopenharmony_cilet getActiveNotificationsCallback = (err: BusinessError, data: Array<notificationManager.NotificationRequest>): void => { 1088e41f4b71Sopenharmony_ci if (err) { 1089e41f4b71Sopenharmony_ci console.error(`getActiveNotifications failed, code is ${err.code}, message is ${err.message}`); 1090e41f4b71Sopenharmony_ci } else { 1091e41f4b71Sopenharmony_ci console.info("getActiveNotifications success" + JSON.stringify(data)); 1092e41f4b71Sopenharmony_ci } 1093e41f4b71Sopenharmony_ci} 1094e41f4b71Sopenharmony_cinotificationManager.getActiveNotifications(getActiveNotificationsCallback); 1095e41f4b71Sopenharmony_ci``` 1096e41f4b71Sopenharmony_ci 1097e41f4b71Sopenharmony_ci## notificationManager.getActiveNotifications 1098e41f4b71Sopenharmony_ci 1099e41f4b71Sopenharmony_cigetActiveNotifications(): Promise\<Array\<NotificationRequest\>\> 1100e41f4b71Sopenharmony_ci 1101e41f4b71Sopenharmony_ci获取当前应用未删除的通知列表。使用Promise异步回调。 1102e41f4b71Sopenharmony_ci 1103e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1104e41f4b71Sopenharmony_ci 1105e41f4b71Sopenharmony_ci**返回值:** 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_ci| 类型 | 说明 | 1108e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------------------- | 1109e41f4b71Sopenharmony_ci| Promise\<Array\<[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)\>\> | 以Promise形式返回获取当前应用通知列表。 | 1110e41f4b71Sopenharmony_ci 1111e41f4b71Sopenharmony_ci**错误码:** 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1116e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1117e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1118e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1119e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1120e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1121e41f4b71Sopenharmony_ci 1122e41f4b71Sopenharmony_ci**示例:** 1123e41f4b71Sopenharmony_ci 1124e41f4b71Sopenharmony_ci```ts 1125e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1126e41f4b71Sopenharmony_ci 1127e41f4b71Sopenharmony_cinotificationManager.getActiveNotifications().then((data: Array<notificationManager.NotificationRequest>) => { 1128e41f4b71Sopenharmony_ci console.info("getActiveNotifications success, data: " + JSON.stringify(data)); 1129e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1130e41f4b71Sopenharmony_ci console.error(`getActiveNotifications fail: ${JSON.stringify(err)}`); 1131e41f4b71Sopenharmony_ci}); 1132e41f4b71Sopenharmony_ci``` 1133e41f4b71Sopenharmony_ci 1134e41f4b71Sopenharmony_ci## notificationManager.cancelGroup 1135e41f4b71Sopenharmony_ci 1136e41f4b71Sopenharmony_cicancelGroup(groupName: string, callback: AsyncCallback\<void\>): void 1137e41f4b71Sopenharmony_ci 1138e41f4b71Sopenharmony_ci取消本应用指定组下的通知。使用callback异步回调。 1139e41f4b71Sopenharmony_ci 1140e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1141e41f4b71Sopenharmony_ci 1142e41f4b71Sopenharmony_ci**参数:** 1143e41f4b71Sopenharmony_ci 1144e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1145e41f4b71Sopenharmony_ci| --------- | --------------------- | ---- | ---------------------------- | 1146e41f4b71Sopenharmony_ci| groupName | string | 是 | 通知组名称,此名称需要在发布通知时通过[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)对象指定。 | 1147e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 取消本应用指定组下通知的回调函数。 | 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ci**错误码:** 1150e41f4b71Sopenharmony_ci 1151e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1154e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1155e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1156e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1157e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1158e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1159e41f4b71Sopenharmony_ci 1160e41f4b71Sopenharmony_ci**示例:** 1161e41f4b71Sopenharmony_ci 1162e41f4b71Sopenharmony_ci```ts 1163e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_cilet cancelGroupCallback = (err: BusinessError): void => { 1166e41f4b71Sopenharmony_ci if (err) { 1167e41f4b71Sopenharmony_ci console.error(`cancelGroup failed, code is ${err.code}, message is ${err.message}`); 1168e41f4b71Sopenharmony_ci } else { 1169e41f4b71Sopenharmony_ci console.info("cancelGroup success"); 1170e41f4b71Sopenharmony_ci } 1171e41f4b71Sopenharmony_ci} 1172e41f4b71Sopenharmony_cilet groupName: string = "GroupName"; 1173e41f4b71Sopenharmony_cinotificationManager.cancelGroup(groupName, cancelGroupCallback); 1174e41f4b71Sopenharmony_ci``` 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ci## notificationManager.cancelGroup 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_cicancelGroup(groupName: string): Promise\<void\> 1179e41f4b71Sopenharmony_ci 1180e41f4b71Sopenharmony_ci取消本应用指定组下的通知。使用Promise异步回调。 1181e41f4b71Sopenharmony_ci 1182e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1183e41f4b71Sopenharmony_ci 1184e41f4b71Sopenharmony_ci**参数:** 1185e41f4b71Sopenharmony_ci 1186e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1187e41f4b71Sopenharmony_ci| --------- | ------ | ---- | -------------- | 1188e41f4b71Sopenharmony_ci| groupName | string | 是 | 通知组名称,此名称需要在发布通知时通过[NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest)对象指定。 | 1189e41f4b71Sopenharmony_ci 1190e41f4b71Sopenharmony_ci**返回值:** 1191e41f4b71Sopenharmony_ci 1192e41f4b71Sopenharmony_ci| 类型 | 说明 | 1193e41f4b71Sopenharmony_ci|---------|-----------| 1194e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 1195e41f4b71Sopenharmony_ci 1196e41f4b71Sopenharmony_ci**错误码:** 1197e41f4b71Sopenharmony_ci 1198e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1199e41f4b71Sopenharmony_ci 1200e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1201e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1202e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1203e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1204e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1205e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1206e41f4b71Sopenharmony_ci 1207e41f4b71Sopenharmony_ci**示例:** 1208e41f4b71Sopenharmony_ci 1209e41f4b71Sopenharmony_ci```ts 1210e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_cilet groupName: string = "GroupName"; 1213e41f4b71Sopenharmony_cinotificationManager.cancelGroup(groupName).then(() => { 1214e41f4b71Sopenharmony_ci console.info("cancelGroup success"); 1215e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1216e41f4b71Sopenharmony_ci console.error(`cancelGroup fail: ${JSON.stringify(err)}`); 1217e41f4b71Sopenharmony_ci}); 1218e41f4b71Sopenharmony_ci``` 1219e41f4b71Sopenharmony_ci 1220e41f4b71Sopenharmony_ci## notificationManager.isSupportTemplate 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_ciisSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): void 1223e41f4b71Sopenharmony_ci 1224e41f4b71Sopenharmony_ci查询模板是否存在。使用callback异步回调。 1225e41f4b71Sopenharmony_ci 1226e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1227e41f4b71Sopenharmony_ci 1228e41f4b71Sopenharmony_ci**参数:** 1229e41f4b71Sopenharmony_ci 1230e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1231e41f4b71Sopenharmony_ci| ------------ | ------------------------ | ---- | -------------------------- | 1232e41f4b71Sopenharmony_ci| templateName | string | 是 | 模板名称。当前仅支持'downloadTemplate'。 | 1233e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean\> | 是 | 查询模板是否存在的回调函数(true:存在,false:不存在)。 | 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ci**错误码:** 1236e41f4b71Sopenharmony_ci 1237e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1238e41f4b71Sopenharmony_ci 1239e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1240e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1241e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1242e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1243e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1244e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1245e41f4b71Sopenharmony_ci 1246e41f4b71Sopenharmony_ci**示例:** 1247e41f4b71Sopenharmony_ci 1248e41f4b71Sopenharmony_ci```ts 1249e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1250e41f4b71Sopenharmony_ci 1251e41f4b71Sopenharmony_cilet templateName: string = 'downloadTemplate'; 1252e41f4b71Sopenharmony_cilet isSupportTemplateCallback = (err: BusinessError, data: boolean): void => { 1253e41f4b71Sopenharmony_ci if (err) { 1254e41f4b71Sopenharmony_ci console.error(`isSupportTemplate failed, code is ${err.code}, message is ${err.message}`); 1255e41f4b71Sopenharmony_ci } else { 1256e41f4b71Sopenharmony_ci console.info("isSupportTemplate success, data: " + JSON.stringify(data)); 1257e41f4b71Sopenharmony_ci } 1258e41f4b71Sopenharmony_ci} 1259e41f4b71Sopenharmony_cinotificationManager.isSupportTemplate(templateName, isSupportTemplateCallback); 1260e41f4b71Sopenharmony_ci``` 1261e41f4b71Sopenharmony_ci 1262e41f4b71Sopenharmony_ci## notificationManager.isSupportTemplate 1263e41f4b71Sopenharmony_ci 1264e41f4b71Sopenharmony_ciisSupportTemplate(templateName: string): Promise\<boolean\> 1265e41f4b71Sopenharmony_ci 1266e41f4b71Sopenharmony_ci查询模板是否存在。使用Promise异步回调。 1267e41f4b71Sopenharmony_ci 1268e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1269e41f4b71Sopenharmony_ci 1270e41f4b71Sopenharmony_ci**参数:** 1271e41f4b71Sopenharmony_ci 1272e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1273e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | -------- | 1274e41f4b71Sopenharmony_ci| templateName | string | 是 | 模板名称。当前仅支持'downloadTemplate'。 | 1275e41f4b71Sopenharmony_ci 1276e41f4b71Sopenharmony_ci**返回值:** 1277e41f4b71Sopenharmony_ci 1278e41f4b71Sopenharmony_ci| 类型 | 说明 | 1279e41f4b71Sopenharmony_ci| ------------------ | --------------- | 1280e41f4b71Sopenharmony_ci| Promise\<boolean\> | Promise方式返回模板是否存在的结果(true:存在,false:不存在)。 | 1281e41f4b71Sopenharmony_ci 1282e41f4b71Sopenharmony_ci**错误码:** 1283e41f4b71Sopenharmony_ci 1284e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1285e41f4b71Sopenharmony_ci 1286e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1287e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1288e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1289e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1290e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1291e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1292e41f4b71Sopenharmony_ci 1293e41f4b71Sopenharmony_ci**示例:** 1294e41f4b71Sopenharmony_ci 1295e41f4b71Sopenharmony_ci```ts 1296e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1297e41f4b71Sopenharmony_ci 1298e41f4b71Sopenharmony_cilet templateName: string = 'downloadTemplate'; 1299e41f4b71Sopenharmony_cinotificationManager.isSupportTemplate(templateName).then((data: boolean) => { 1300e41f4b71Sopenharmony_ci console.info("isSupportTemplate success, data: " + JSON.stringify(data)); 1301e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1302e41f4b71Sopenharmony_ci console.error(`isSupportTemplate fail: ${JSON.stringify(err)}`); 1303e41f4b71Sopenharmony_ci}); 1304e41f4b71Sopenharmony_ci``` 1305e41f4b71Sopenharmony_ci 1306e41f4b71Sopenharmony_ci## notificationManager.requestEnableNotification<sup>(deprecated)</sup> 1307e41f4b71Sopenharmony_ci 1308e41f4b71Sopenharmony_cirequestEnableNotification(callback: AsyncCallback\<void\>): void 1309e41f4b71Sopenharmony_ci 1310e41f4b71Sopenharmony_ci应用请求通知使能。使用callback异步回调。 1311e41f4b71Sopenharmony_ci 1312e41f4b71Sopenharmony_ci> **说明:** 1313e41f4b71Sopenharmony_ci> 1314e41f4b71Sopenharmony_ci> 从API version 12开始不再维护,建议使用有context入参的[requestEnableNotification](#notificationmanagerrequestenablenotification10)代替。 1315e41f4b71Sopenharmony_ci 1316e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1317e41f4b71Sopenharmony_ci 1318e41f4b71Sopenharmony_ci**参数:** 1319e41f4b71Sopenharmony_ci 1320e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1321e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- | -------------------------- | 1322e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 应用请求通知使能的回调函数。 | 1323e41f4b71Sopenharmony_ci 1324e41f4b71Sopenharmony_ci**错误码:** 1325e41f4b71Sopenharmony_ci 1326e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1327e41f4b71Sopenharmony_ci 1328e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1329e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1330e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1331e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1332e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1333e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1334e41f4b71Sopenharmony_ci| 1600004 | Notification disabled. | 1335e41f4b71Sopenharmony_ci| 1600013 | A notification dialog box is already displayed. | 1336e41f4b71Sopenharmony_ci 1337e41f4b71Sopenharmony_ci**示例:** 1338e41f4b71Sopenharmony_ci 1339e41f4b71Sopenharmony_ci```ts 1340e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1341e41f4b71Sopenharmony_ci 1342e41f4b71Sopenharmony_cilet requestEnableNotificationCallback = (err: BusinessError): void => { 1343e41f4b71Sopenharmony_ci if (err) { 1344e41f4b71Sopenharmony_ci console.error(`requestEnableNotification failed, code is ${err.code}, message is ${err.message}`); 1345e41f4b71Sopenharmony_ci } else { 1346e41f4b71Sopenharmony_ci console.info("requestEnableNotification success"); 1347e41f4b71Sopenharmony_ci } 1348e41f4b71Sopenharmony_ci}; 1349e41f4b71Sopenharmony_cinotificationManager.requestEnableNotification(requestEnableNotificationCallback); 1350e41f4b71Sopenharmony_ci``` 1351e41f4b71Sopenharmony_ci 1352e41f4b71Sopenharmony_ci## notificationManager.requestEnableNotification<sup>(deprecated)</sup> 1353e41f4b71Sopenharmony_ci 1354e41f4b71Sopenharmony_cirequestEnableNotification(): Promise\<void\> 1355e41f4b71Sopenharmony_ci 1356e41f4b71Sopenharmony_ci应用请求通知使能。使用Promise异步回调。 1357e41f4b71Sopenharmony_ci 1358e41f4b71Sopenharmony_ci> **说明:** 1359e41f4b71Sopenharmony_ci> 1360e41f4b71Sopenharmony_ci> 从API version 12开始不再维护,建议使用有context入参的[requestEnableNotification](#notificationmanagerrequestenablenotification10-1)代替。 1361e41f4b71Sopenharmony_ci 1362e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1363e41f4b71Sopenharmony_ci 1364e41f4b71Sopenharmony_ci**返回值:** 1365e41f4b71Sopenharmony_ci 1366e41f4b71Sopenharmony_ci| 类型 | 说明 | 1367e41f4b71Sopenharmony_ci|---------|-----------| 1368e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 1369e41f4b71Sopenharmony_ci 1370e41f4b71Sopenharmony_ci**错误码:** 1371e41f4b71Sopenharmony_ci 1372e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1373e41f4b71Sopenharmony_ci 1374e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1375e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1376e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1377e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1378e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1379e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1380e41f4b71Sopenharmony_ci| 1600004 | Notification disabled. | 1381e41f4b71Sopenharmony_ci| 1600013 | A notification dialog box is already displayed. | 1382e41f4b71Sopenharmony_ci 1383e41f4b71Sopenharmony_ci**示例:** 1384e41f4b71Sopenharmony_ci 1385e41f4b71Sopenharmony_ci```ts 1386e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1387e41f4b71Sopenharmony_ci 1388e41f4b71Sopenharmony_cinotificationManager.requestEnableNotification().then(() => { 1389e41f4b71Sopenharmony_ci console.info("requestEnableNotification success"); 1390e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1391e41f4b71Sopenharmony_ci console.error(`requestEnableNotification fail: ${JSON.stringify(err)}`); 1392e41f4b71Sopenharmony_ci}); 1393e41f4b71Sopenharmony_ci``` 1394e41f4b71Sopenharmony_ci 1395e41f4b71Sopenharmony_ci## notificationManager.requestEnableNotification<sup>10+</sup> 1396e41f4b71Sopenharmony_ci 1397e41f4b71Sopenharmony_cirequestEnableNotification(context: UIAbilityContext, callback: AsyncCallback\<void\>): void 1398e41f4b71Sopenharmony_ci 1399e41f4b71Sopenharmony_ci应用请求通知使能模态弹窗。使用callback异步回调。 1400e41f4b71Sopenharmony_ci 1401e41f4b71Sopenharmony_ci仅当应用界面加载完成后(即调用[loadContent](../apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md#uiextensioncontentsessionloadcontent)成功),方可使用该接口。 1402e41f4b71Sopenharmony_ci 1403e41f4b71Sopenharmony_ci**模型约束**:此接口仅可在Stage模型下使用。 1404e41f4b71Sopenharmony_ci 1405e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1406e41f4b71Sopenharmony_ci 1407e41f4b71Sopenharmony_ci**参数:** 1408e41f4b71Sopenharmony_ci 1409e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1410e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- |--------------------| 1411e41f4b71Sopenharmony_ci| context | [UIAbilityContext](../../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | 是 | 通知弹窗绑定Ability的上下文。 | 1412e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | 是 | 应用请求通知使能的回调函数。 | 1413e41f4b71Sopenharmony_ci 1414e41f4b71Sopenharmony_ci**错误码:** 1415e41f4b71Sopenharmony_ci 1416e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1417e41f4b71Sopenharmony_ci 1418e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1419e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1420e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1421e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1422e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1423e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1424e41f4b71Sopenharmony_ci| 1600004 | Notification disabled. | 1425e41f4b71Sopenharmony_ci| 1600013 | A notification dialog box is already displayed. | 1426e41f4b71Sopenharmony_ci 1427e41f4b71Sopenharmony_ci**示例:** 1428e41f4b71Sopenharmony_ci 1429e41f4b71Sopenharmony_ci```ts 1430e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1431e41f4b71Sopenharmony_ciimport { UIAbility } from '@kit.AbilityKit'; 1432e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 1433e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit'; 1434e41f4b71Sopenharmony_ci 1435e41f4b71Sopenharmony_ciclass MyAbility extends UIAbility { 1436e41f4b71Sopenharmony_ci onWindowStageCreate(windowStage: window.WindowStage) { 1437e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 1438e41f4b71Sopenharmony_ci windowStage.loadContent('pages/Index', (err, data) => { 1439e41f4b71Sopenharmony_ci if (err.code) { 1440e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 1441e41f4b71Sopenharmony_ci return; 1442e41f4b71Sopenharmony_ci } 1443e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); 1444e41f4b71Sopenharmony_ci let requestEnableNotificationCallback = (err: BusinessError): void => { 1445e41f4b71Sopenharmony_ci if (err) { 1446e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`); 1447e41f4b71Sopenharmony_ci } else { 1448e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', `[ANS] requestEnableNotification success`); 1449e41f4b71Sopenharmony_ci } 1450e41f4b71Sopenharmony_ci }; 1451e41f4b71Sopenharmony_ci notificationManager.requestEnableNotification(this.context, requestEnableNotificationCallback); 1452e41f4b71Sopenharmony_ci }); 1453e41f4b71Sopenharmony_ci } 1454e41f4b71Sopenharmony_ci} 1455e41f4b71Sopenharmony_ci``` 1456e41f4b71Sopenharmony_ci 1457e41f4b71Sopenharmony_ci## notificationManager.requestEnableNotification<sup>10+</sup> 1458e41f4b71Sopenharmony_ci 1459e41f4b71Sopenharmony_cirequestEnableNotification(context: UIAbilityContext): Promise\<void\> 1460e41f4b71Sopenharmony_ci 1461e41f4b71Sopenharmony_ci应用请求通知使能模态弹窗。使用Promise异步回调。 1462e41f4b71Sopenharmony_ci 1463e41f4b71Sopenharmony_ci仅当应用界面加载完成后(即调用[loadContent](../apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md#uiextensioncontentsessionloadcontent)成功),方可使用该接口。 1464e41f4b71Sopenharmony_ci 1465e41f4b71Sopenharmony_ci**模型约束**:此接口仅可在Stage模型下使用。 1466e41f4b71Sopenharmony_ci 1467e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1468e41f4b71Sopenharmony_ci 1469e41f4b71Sopenharmony_ci**参数:** 1470e41f4b71Sopenharmony_ci 1471e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1472e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- |--------------------| 1473e41f4b71Sopenharmony_ci| context | [UIAbilityContext](../../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | 是 | 通知弹窗绑定Ability的上下文。 | 1474e41f4b71Sopenharmony_ci 1475e41f4b71Sopenharmony_ci**返回值:** 1476e41f4b71Sopenharmony_ci 1477e41f4b71Sopenharmony_ci| 类型 | 说明 | 1478e41f4b71Sopenharmony_ci|---------|-----------| 1479e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 1480e41f4b71Sopenharmony_ci 1481e41f4b71Sopenharmony_ci**错误码:** 1482e41f4b71Sopenharmony_ci 1483e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1484e41f4b71Sopenharmony_ci 1485e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1486e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1487e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1488e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1489e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1490e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1491e41f4b71Sopenharmony_ci| 1600004 | Notification disabled. | 1492e41f4b71Sopenharmony_ci| 1600013 | A notification dialog box is already displayed. | 1493e41f4b71Sopenharmony_ci 1494e41f4b71Sopenharmony_ci**示例:** 1495e41f4b71Sopenharmony_ci 1496e41f4b71Sopenharmony_ci```ts 1497e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1498e41f4b71Sopenharmony_ciimport { UIAbility } from '@kit.AbilityKit'; 1499e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 1500e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit'; 1501e41f4b71Sopenharmony_ci 1502e41f4b71Sopenharmony_ciclass MyAbility extends UIAbility { 1503e41f4b71Sopenharmony_ci onWindowStageCreate(windowStage: window.WindowStage) { 1504e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 1505e41f4b71Sopenharmony_ci windowStage.loadContent('pages/Index', (err, data) => { 1506e41f4b71Sopenharmony_ci if (err.code) { 1507e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 1508e41f4b71Sopenharmony_ci return; 1509e41f4b71Sopenharmony_ci } 1510e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); 1511e41f4b71Sopenharmony_ci notificationManager.requestEnableNotification(this.context).then(() => { 1512e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', `[ANS] requestEnableNotification success`); 1513e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1514e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`); 1515e41f4b71Sopenharmony_ci }); 1516e41f4b71Sopenharmony_ci }); 1517e41f4b71Sopenharmony_ci } 1518e41f4b71Sopenharmony_ci} 1519e41f4b71Sopenharmony_ci``` 1520e41f4b71Sopenharmony_ci 1521e41f4b71Sopenharmony_ci## notificationManager.isDistributedEnabled 1522e41f4b71Sopenharmony_ci 1523e41f4b71Sopenharmony_ciisDistributedEnabled(callback: AsyncCallback\<boolean>): void 1524e41f4b71Sopenharmony_ci 1525e41f4b71Sopenharmony_ci查询设备是否支持分布式通知。使用callback异步回调。 1526e41f4b71Sopenharmony_ci 1527e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1528e41f4b71Sopenharmony_ci 1529e41f4b71Sopenharmony_ci**参数:** 1530e41f4b71Sopenharmony_ci 1531e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1532e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- | -------------------------- | 1533e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean\> | 是 | 设备是否支持分布式通知的回调函数(true:支持,false:不支持)。 | 1534e41f4b71Sopenharmony_ci 1535e41f4b71Sopenharmony_ci**错误码:** 1536e41f4b71Sopenharmony_ci 1537e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1538e41f4b71Sopenharmony_ci 1539e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1540e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1541e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1542e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1543e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1544e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1545e41f4b71Sopenharmony_ci| 1600010 | Distributed operation failed. | 1546e41f4b71Sopenharmony_ci 1547e41f4b71Sopenharmony_ci**示例:** 1548e41f4b71Sopenharmony_ci 1549e41f4b71Sopenharmony_ci```ts 1550e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1551e41f4b71Sopenharmony_ci 1552e41f4b71Sopenharmony_cilet isDistributedEnabledCallback = (err: BusinessError, data: boolean): void => { 1553e41f4b71Sopenharmony_ci if (err) { 1554e41f4b71Sopenharmony_ci console.error(`isDistributedEnabled failed, code is ${err.code}, message is ${err.message}`); 1555e41f4b71Sopenharmony_ci } else { 1556e41f4b71Sopenharmony_ci console.info("isDistributedEnabled success " + JSON.stringify(data)); 1557e41f4b71Sopenharmony_ci } 1558e41f4b71Sopenharmony_ci}; 1559e41f4b71Sopenharmony_cinotificationManager.isDistributedEnabled(isDistributedEnabledCallback); 1560e41f4b71Sopenharmony_ci``` 1561e41f4b71Sopenharmony_ci 1562e41f4b71Sopenharmony_ci## notificationManager.isDistributedEnabled 1563e41f4b71Sopenharmony_ci 1564e41f4b71Sopenharmony_ciisDistributedEnabled(): Promise\<boolean> 1565e41f4b71Sopenharmony_ci 1566e41f4b71Sopenharmony_ci查询设备是否支持分布式通知。使用Promise异步回调。 1567e41f4b71Sopenharmony_ci 1568e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.Notification 1569e41f4b71Sopenharmony_ci 1570e41f4b71Sopenharmony_ci**返回值:** 1571e41f4b71Sopenharmony_ci 1572e41f4b71Sopenharmony_ci| 类型 | 说明 | 1573e41f4b71Sopenharmony_ci| ------------------ | --------------------------------------------- | 1574e41f4b71Sopenharmony_ci| Promise\<boolean\> | Promise方式返回设备是否支持分布式通知的结果(true:支持,false:不支持)。 | 1575e41f4b71Sopenharmony_ci 1576e41f4b71Sopenharmony_ci**错误码:** 1577e41f4b71Sopenharmony_ci 1578e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1579e41f4b71Sopenharmony_ci 1580e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1581e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1582e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 1583e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1584e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 1585e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1586e41f4b71Sopenharmony_ci| 1600010 | Distributed operation failed. | 1587e41f4b71Sopenharmony_ci 1588e41f4b71Sopenharmony_ci**示例:** 1589e41f4b71Sopenharmony_ci 1590e41f4b71Sopenharmony_ci```ts 1591e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1592e41f4b71Sopenharmony_ci 1593e41f4b71Sopenharmony_cinotificationManager.isDistributedEnabled().then((data: boolean) => { 1594e41f4b71Sopenharmony_ci console.info("isDistributedEnabled success, data: " + JSON.stringify(data)); 1595e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1596e41f4b71Sopenharmony_ci console.error(`isDistributedEnabled fail: ${JSON.stringify(err)}`); 1597e41f4b71Sopenharmony_ci}); 1598e41f4b71Sopenharmony_ci``` 1599e41f4b71Sopenharmony_ci 1600e41f4b71Sopenharmony_ci## notificationManager.openNotificationSettings<sup>13+</sup> 1601e41f4b71Sopenharmony_ci 1602e41f4b71Sopenharmony_ciopenNotificationSettings(context: UIAbilityContext): Promise\<void\> 1603e41f4b71Sopenharmony_ci 1604e41f4b71Sopenharmony_ci拉起应用的通知设置界面,该页面以半模态形式呈现,可用于设置通知开关、通知提醒方式等。使用Promise异步回调。 1605e41f4b71Sopenharmony_ci 1606e41f4b71Sopenharmony_ci**模型约束**:此接口仅可在Stage模型下使用。 1607e41f4b71Sopenharmony_ci 1608e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Notification.NotificationSettings 1609e41f4b71Sopenharmony_ci 1610e41f4b71Sopenharmony_ci**参数:** 1611e41f4b71Sopenharmony_ci 1612e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1613e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- |--------------------| 1614e41f4b71Sopenharmony_ci| context | [UIAbilityContext](../../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | 是 | 通知设置页面绑定Ability的上下文。 | 1615e41f4b71Sopenharmony_ci 1616e41f4b71Sopenharmony_ci**返回值:** 1617e41f4b71Sopenharmony_ci 1618e41f4b71Sopenharmony_ci| 类型 | 说明 | 1619e41f4b71Sopenharmony_ci|---------|-----------| 1620e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回结果的Promise对象。 | 1621e41f4b71Sopenharmony_ci 1622e41f4b71Sopenharmony_ci**错误码:** 1623e41f4b71Sopenharmony_ci 1624e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[通知错误码](./errorcode-notification.md)。 1625e41f4b71Sopenharmony_ci 1626e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1627e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1628e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 1629e41f4b71Sopenharmony_ci| 1600003 | Failed to connect to the service. | 1630e41f4b71Sopenharmony_ci| 1600018 | the notification settings window is already displayed. | 1631e41f4b71Sopenharmony_ci 1632e41f4b71Sopenharmony_ci**示例:** 1633e41f4b71Sopenharmony_ci 1634e41f4b71Sopenharmony_ci```ts 1635e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1636e41f4b71Sopenharmony_ciimport { UIAbility } from '@kit.AbilityKit'; 1637e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 1638e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit'; 1639e41f4b71Sopenharmony_ci 1640e41f4b71Sopenharmony_ciclass MyAbility extends UIAbility { 1641e41f4b71Sopenharmony_ci onWindowStageCreate(windowStage: window.WindowStage) { 1642e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 1643e41f4b71Sopenharmony_ci windowStage.loadContent('pages/Index', (err, data) => { 1644e41f4b71Sopenharmony_ci if (err.code) { 1645e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 1646e41f4b71Sopenharmony_ci return; 1647e41f4b71Sopenharmony_ci } 1648e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); 1649e41f4b71Sopenharmony_ci notificationManager.openNotificationSettings(this.context).then(() => { 1650e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', `[ANS] openNotificationSettings success`); 1651e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1652e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `[ANS] openNotificationSettings failed, code is ${err.code}, message is ${err.message}`); 1653e41f4b71Sopenharmony_ci }); 1654e41f4b71Sopenharmony_ci }); 1655e41f4b71Sopenharmony_ci } 1656e41f4b71Sopenharmony_ci} 1657e41f4b71Sopenharmony_ci``` 1658e41f4b71Sopenharmony_ci 1659e41f4b71Sopenharmony_ci## ContentType 1660e41f4b71Sopenharmony_ci 1661e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1662e41f4b71Sopenharmony_ci 1663e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 1664e41f4b71Sopenharmony_ci 1665e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 1666e41f4b71Sopenharmony_ci| --------------------------------- | ----------- |------------------| 1667e41f4b71Sopenharmony_ci| NOTIFICATION_CONTENT_BASIC_TEXT | 0 | 普通类型通知。 | 1668e41f4b71Sopenharmony_ci| NOTIFICATION_CONTENT_LONG_TEXT | 1 | 长文本类型通知。 | 1669e41f4b71Sopenharmony_ci| NOTIFICATION_CONTENT_PICTURE | 2 | 图片类型通知。 | 1670e41f4b71Sopenharmony_ci| NOTIFICATION_CONTENT_CONVERSATION | 3 | 社交类型通知。预留能力,暂未支持。| 1671e41f4b71Sopenharmony_ci| NOTIFICATION_CONTENT_MULTILINE | 4 | 多行文本类型通知。 | 1672e41f4b71Sopenharmony_ci| NOTIFICATION_CONTENT_SYSTEM_LIVE_VIEW<sup>11+</sup> | 5 | 实况窗类型通知。不支持三方应用直接创建该类型通知,可以由系统代理创建系统实况窗类型通知后,三方应用发布同ID的通知来更新指定内容。| 1673e41f4b71Sopenharmony_ci| NOTIFICATION_CONTENT_LIVE_VIEW<sup>11+</sup> | 6 | 普通实况窗类型通知。只支持系统应用。 | 1674e41f4b71Sopenharmony_ci 1675e41f4b71Sopenharmony_ci## SlotLevel 1676e41f4b71Sopenharmony_ci 1677e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 1678e41f4b71Sopenharmony_ci 1679e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 1680e41f4b71Sopenharmony_ci| --------------------------------- | ----------- | ------------------ | 1681e41f4b71Sopenharmony_ci| LEVEL_NONE | 0 | 表示关闭通知功能。 | 1682e41f4b71Sopenharmony_ci| LEVEL_MIN | 1 | 表示通知功能已启用,但状态栏中不显示通知图标,且没有横幅或提示音。 | 1683e41f4b71Sopenharmony_ci| LEVEL_LOW | 2 | 表示通知功能已启用,且状态栏中显示通知图标,但没有横幅或提示音。 | 1684e41f4b71Sopenharmony_ci| LEVEL_DEFAULT | 3 | 表示通知功能已启用,状态栏中显示通知图标,没有横幅但有提示音。 | 1685e41f4b71Sopenharmony_ci| LEVEL_HIGH | 4 | 表示通知功能已启用,状态栏中显示通知图标,有横幅和提示音。 | 1686e41f4b71Sopenharmony_ci 1687e41f4b71Sopenharmony_ci 1688e41f4b71Sopenharmony_ci## SlotType 1689e41f4b71Sopenharmony_ci 1690e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1691e41f4b71Sopenharmony_ci 1692e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification 1693e41f4b71Sopenharmony_ci 1694e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 1695e41f4b71Sopenharmony_ci| -------------------- | -------- | ---------- | 1696e41f4b71Sopenharmony_ci| UNKNOWN_TYPE | 0 | 未知类型。该类型对应[SlotLevel](#slotlevel)为LEVEL_MIN。 | 1697e41f4b71Sopenharmony_ci| SOCIAL_COMMUNICATION | 1 | 社交通信。该类型对应[SlotLevel](#slotlevel)为LEVEL_HIGH。 | 1698e41f4b71Sopenharmony_ci| SERVICE_INFORMATION | 2 | 服务提醒。该类型对应[SlotLevel](#slotlevel)为LEVEL_HIGH。| 1699e41f4b71Sopenharmony_ci| CONTENT_INFORMATION | 3 | 内容资讯。该类型对应[SlotLevel](#slotlevel)为LEVEL_MIN。 | 1700e41f4b71Sopenharmony_ci| LIVE_VIEW<sup>11+</sup> | 4 | 实况窗。不支持三方应用直接创建该渠道类型通知,可以由系统代理创建后,三方应用发布同ID的通知来更新指定内容。该类型对应[SlotLevel](#slotlevel)为LEVEL_DEFAULT。 | 1701e41f4b71Sopenharmony_ci| CUSTOMER_SERVICE<sup>11+</sup> | 5 | 客服消息。该类型用于用户与商家之间的客服消息,需由用户主动发起。该类型对应[SlotLevel](#slotlevel)为LEVEL_DEFAULT。 | 1702e41f4b71Sopenharmony_ci| OTHER_TYPES | 0xFFFF | 其他。该类型对应[SlotLevel](#slotlevel)为LEVEL_MIN。 | 1703