1# Requesting Notification Authorization
2
3Your application can send notifications only after obtaining user authorization. Call the [requestEnableNotification()](../reference/apis-notification-kit/js-apis-notificationManager.md#notificationmanagerrequestenablenotification10-1) API before a notification is published. A dialog box is displayed for the user to determine whether to allow notification sending. When this API is called again, no dialog box is displayed.
4
5## Available APIs
6
7For details about the APIs, see [@ohos.notificationManager (NotificationManager)](../reference/apis-notification-kit/js-apis-notificationManager.md#notificationmanagerrequestenablenotification10-1).
8
9**Table 1** Notification authorization APIs
10
11| **API** | **Description**|
12| -------- | -------- |
13| isNotificationEnabled():Promise\<boolean\>       | Checks whether notification is enabled. |
14| requestEnableNotification(context: UIAbilityContext): Promise\<void\> | Requests notification to be enabled. When called for the first time, this API displays a dialog box prompting the user to select.    |
15
16
17## How to Develop
18
191. Import the **NotificationManager** module.
20
21    ```ts
22    import { notificationManager } from '@kit.NotificationKit';
23    import { BusinessError } from '@kit.BasicServicesKit';
24    import { hilog } from '@kit.PerformanceAnalysisKit';
25    import { common } from '@kit.AbilityKit';
26
27    const TAG: string = '[PublishOperation]';
28    const DOMAIN_NUMBER: number = 0xFF00;
29    ```
30
312. Request notification to be enabled.
32
33    You can determine whether the user has authorized the request based on the error code of **requestEnableNotification**. If the error code **1600004** is returned, the authorization is rejected.
34
35    ```ts
36    let context = getContext(this) as common.UIAbilityContext;
37    notificationManager.isNotificationEnabled().then((data: boolean) => {
38      hilog.info(DOMAIN_NUMBER, TAG, "isNotificationEnabled success, data: " + JSON.stringify(data));
39      if(!data){
40        notificationManager.requestEnableNotification(context).then(() => {
41          hilog.info(DOMAIN_NUMBER, TAG, `[ANS] requestEnableNotification success`);
42        }).catch((err : BusinessError) => {
43          if(1600004 == err.code){
44            hilog.error(DOMAIN_NUMBER, TAG, `[ANS] requestEnableNotification refused, code is ${err.code}, message is ${err.message}`);
45          } else {
46            hilog.error(DOMAIN_NUMBER, TAG, `[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`);
47          }
48        });
49      }
50    }).catch((err : BusinessError) => {
51        hilog.error(DOMAIN_NUMBER, TAG, `isNotificationEnabled fail, code is ${err.code}, message is ${err.message}`);
52    });
53    ```
54