通知管理的能力

2024-01-23 12:59 更新

本模塊提供通知管理的能力,包括發(fā)布、取消發(fā)布通知,創(chuàng)建、獲取、移除通知通道,獲取通知的使能狀態(tài)、角標(biāo)使能狀態(tài),獲取通知的相關(guān)信息等。

說明

本模塊首批接口從API version 9開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。

導(dǎo)入模塊

  1. import Notification from '@ohos.notificationManager';

Notification.publish

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

發(fā)布通知(callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

request

NotificationRequest

用于設(shè)置要發(fā)布通知的內(nèi)容和相關(guān)配置信息。

callback

AsyncCallback<void>

發(fā)布通知的回調(diào)方法。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

1600004

Notification is not enabled.

1600005

Notification slot is not enabled.

1600009

Over max number notifications per second.

示例:

  1. //publish回調(diào)
  2. function publishCallback(err) {
  3. if (err) {
  4. console.info("publish failed " + JSON.stringify(err));
  5. } else {
  6. console.info("publish success");
  7. }
  8. }
  9. //通知Request對象
  10. let notificationRequest = {
  11. id: 1,
  12. content: {
  13. contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
  14. normal: {
  15. title: "test_title",
  16. text: "test_text",
  17. additionalText: "test_additionalText"
  18. }
  19. }
  20. };
  21. Notification.publish(notificationRequest, publishCallback);

Notification.publish

publish(request: NotificationRequest): Promise<void>

發(fā)布通知(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

request

NotificationRequest

用于設(shè)置要發(fā)布通知的內(nèi)容和相關(guān)配置信息。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

1600004

Notification is not enabled.

1600005

Notification slot is not enabled.

1600009

Over max number notifications per second.

示例:

  1. // 通知Request對象
  2. let notificationRequest = {
  3. notificationId: 1,
  4. content: {
  5. contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
  6. normal: {
  7. title: "test_title",
  8. text: "test_text",
  9. additionalText: "test_additionalText"
  10. }
  11. }
  12. };
  13. Notification.publish(notificationRequest).then(() => {
  14. console.info("publish success");
  15. });

Notification.cancel

cancel(id: number, label: string, callback: AsyncCallback<void>): void

通過通知ID和通知標(biāo)簽取消已發(fā)布的通知(callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

id

number

通知ID。

label

string

通知標(biāo)簽。

callback

AsyncCallback<void>

表示被指定的回調(diào)方法。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

1600007

The notification is not exist.

示例:

  1. // cancel回調(diào)
  2. function cancelCallback(err) {
  3. if (err) {
  4. console.info("cancel failed " + JSON.stringify(err));
  5. } else {
  6. console.info("cancel success");
  7. }
  8. }
  9. Notification.cancel(0, "label", cancelCallback);

Notification.cancel

cancel(id: number, label?: string): Promise<void>

取消與指定通知ID相匹配的已發(fā)布通知,label可以指定也可以不指定(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

id

number

通知ID。

label

string

通知標(biāo)簽。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

1600007

The notification is not exist.

示例:

  1. Notification.cancel(0).then(() => {
  2. console.info("cancel success");
  3. });

Notification.cancel

cancel(id: number, callback: AsyncCallback<void>): void

取消與指定通知ID相匹配的已發(fā)布通知(callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

id

number

通知ID。

callback

AsyncCallback<void>

表示被指定的回調(diào)方法。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

1600007

The notification is not exist.

示例:

  1. // cancel回調(diào)
  2. function cancelCallback(err) {
  3. if (err) {
  4. console.info("cancel failed " + JSON.stringify(err));
  5. } else {
  6. console.info("cancel success");
  7. }
  8. }
  9. Notification.cancel(0, cancelCallback);

Notification.cancelAll

cancelAll(callback: AsyncCallback<void>): void

取消所有已發(fā)布的通知(callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<void>

表示被指定的回調(diào)方法。

示例:

  1. // cancel回調(diào)
  2. function cancelAllCallback(err) {
  3. if (err) {
  4. console.info("cancelAll failed " + JSON.stringify(err));
  5. } else {
  6. console.info("cancelAll success");
  7. }
  8. }
  9. Notification.cancelAll(cancelAllCallback);

Notification.cancelAll

cancelAll(): Promise<void>

取消所有已發(fā)布的通知(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. Notification.cancelAll().then(() => {
  2. console.info("cancelAll success");
  3. });

Notification.addSlot

addSlot(type: SlotType, callback: AsyncCallback<void>): void

創(chuàng)建指定類型的通知通道(callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

type

SlotType

要?jiǎng)?chuàng)建的通知通道的類型。

callback

AsyncCallback<void>

表示被指定的回調(diào)方法。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. // addslot回調(diào)
  2. function addSlotCallBack(err) {
  3. if (err) {
  4. console.info("addSlot failed " + JSON.stringify(err));
  5. } else {
  6. console.info("addSlot success");
  7. }
  8. }
  9. Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack);

Notification.addSlot

addSlot(type: SlotType): Promise<void>

創(chuàng)建指定類型的通知通道(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

type

SlotType

要?jiǎng)?chuàng)建的通知通道的類型。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
  2. console.info("addSlot success");
  3. });

Notification.getSlot

getSlot(slotType: SlotType, callback: AsyncCallback<NotificationSlot>): void

獲取一個(gè)指定類型的通知通道(callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

slotType

SlotType

通知渠道類型,目前分為社交通信、服務(wù)提醒、內(nèi)容咨詢和其他類型。

callback

AsyncCallback<NotificationSlot>

表示被指定的回調(diào)方法。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. // getSlot回調(diào)
  2. function getSlotCallback(err,data) {
  3. if (err) {
  4. console.info("getSlot failed " + JSON.stringify(err));
  5. } else {
  6. console.info("getSlot success");
  7. }
  8. }
  9. let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
  10. Notification.getSlot(slotType, getSlotCallback);

Notification.getSlot

getSlot(slotType: SlotType): Promise<NotificationSlot>

獲取一個(gè)指定類型的通知通道(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

slotType

SlotType

通知渠道類型,目前分為社交通信、服務(wù)提醒、內(nèi)容咨詢和其他類型。

返回值:

類型

說明

Promise<NotificationSlot>

以Promise形式返回獲取一個(gè)通知通道。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
  2. Notification.getSlot(slotType).then((data) => {
  3. console.info("getSlot success, data: " + JSON.stringify(data));
  4. });

Notification.getSlots

getSlots(callback: AsyncCallback<Array<NotificationSlot>>): void

獲取此應(yīng)用程序的所有通知通道(callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<Array<NotificationSlot>>

以callback形式返回獲取此應(yīng)用程序的所有通知通道的結(jié)果。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. // getSlots回調(diào)
  2. function getSlotsCallback(err,data) {
  3. if (err) {
  4. console.info("getSlots failed " + JSON.stringify(err));
  5. } else {
  6. console.info("getSlots success");
  7. }
  8. }
  9. Notification.getSlots(getSlotsCallback);

Notification.getSlots

getSlots(): Promise<Array<NotificationSlot>>

獲取此應(yīng)用程序的所有通知通道(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

返回值:

類型

說明

Promise<Array<NotificationSlot>>

以Promise形式返回獲取此應(yīng)用程序的所有通知通道的結(jié)果。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. Notification.getSlots().then((data) => {
  2. console.info("getSlots success, data: " + JSON.stringify(data));
  3. });

Notification.removeSlot

removeSlot(slotType: SlotType, callback: AsyncCallback<void>): void

刪除指定類型的通知通道(callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

slotType

SlotType

通知渠道類型,目前分為社交通信、服務(wù)提醒、內(nèi)容咨詢和其他類型。

callback

AsyncCallback<void>

表示被指定的回調(diào)方法。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. // removeSlot回調(diào)
  2. function removeSlotCallback(err) {
  3. if (err) {
  4. console.info("removeSlot failed " + JSON.stringify(err));
  5. } else {
  6. console.info("removeSlot success");
  7. }
  8. }
  9. let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
  10. Notification.removeSlot(slotType,removeSlotCallback);

Notification.removeSlot

removeSlot(slotType: SlotType): Promise<void>

刪除指定類型的通知通道(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

slotType

SlotType

通知渠道類型,目前分為社交通信、服務(wù)提醒、內(nèi)容咨詢和其他類型。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
  2. Notification.removeSlot(slotType).then(() => {
  3. console.info("removeSlot success");
  4. });

Notification.removeAllSlots

removeAllSlots(callback: AsyncCallback<void>): void

刪除所有通知通道(callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<void>

表示被指定的回調(diào)方法。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. function removeAllCallBack(err) {
  2. if (err) {
  3. console.info("removeAllSlots failed " + JSON.stringify(err));
  4. } else {
  5. console.info("removeAllSlots success");
  6. }
  7. }
  8. Notification.removeAllSlots(removeAllCallBack);

Notification.removeAllSlots

removeAllSlots(): Promise<void>

刪除所有通知通道(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. Notification.removeAllSlots().then(() => {
  2. console.info("removeAllSlots success");
  3. });

Notification.getActiveNotificationCount

getActiveNotificationCount(callback: AsyncCallback<number>): void

獲取當(dāng)前應(yīng)用未刪除的通知數(shù)(Callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<number>

獲取未刪除通知數(shù)回調(diào)函數(shù)。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. function getActiveNotificationCountCallback(err, data) {
  2. if (err) {
  3. console.info("getActiveNotificationCount failed " + JSON.stringify(err));
  4. } else {
  5. console.info("getActiveNotificationCount success");
  6. }
  7. }
  8. Notification.getActiveNotificationCount(getActiveNotificationCountCallback);

Notification.getActiveNotificationCount

getActiveNotificationCount(): Promise<number>

獲取當(dāng)前應(yīng)用未刪除的通知數(shù)(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

返回值:

類型

說明

Promise<number>

以Promise形式返回獲取當(dāng)前應(yīng)用未刪除通知數(shù)。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. Notification.getActiveNotificationCount().then((data) => {
  2. console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
  3. });

Notification.getActiveNotifications

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

獲取當(dāng)前應(yīng)用未刪除的通知列表(Callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<Array<NotificationRequest>>

獲取當(dāng)前應(yīng)用通知列表回調(diào)函數(shù)。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. function getActiveNotificationsCallback(err, data) {
  2. if (err) {
  3. console.info("getActiveNotifications failed " + JSON.stringify(err));
  4. } else {
  5. console.info("getActiveNotifications success");
  6. }
  7. }
  8. Notification.getActiveNotifications(getActiveNotificationsCallback);

Notification.getActiveNotifications

getActiveNotifications(): Promise<Array<NotificationRequest>>

獲取當(dāng)前應(yīng)用未刪除的通知列表(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

返回值:

類型

說明

Promise<Array<NotificationRequest>>

以Promise形式返回獲取當(dāng)前應(yīng)用通知列表。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. Notification.getActiveNotifications().then((data) => {
  2. console.info("removeGroupByBundle success, data: " + JSON.stringify(data));
  3. });

Notification.cancelGroup

cancelGroup(groupName: string, callback: AsyncCallback<void>): void

取消本應(yīng)用指定組下的通知(Callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

groupName

string

通知組名稱,此名稱需要在發(fā)布通知時(shí)通過NotificationRequest對象指定。

callback

AsyncCallback<void>

取消本應(yīng)用指定組下通知的回調(diào)函數(shù)。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. function cancelGroupCallback(err) {
  2. if (err) {
  3. console.info("cancelGroup failed " + JSON.stringify(err));
  4. } else {
  5. console.info("cancelGroup success");
  6. }
  7. }
  8. let groupName = "GroupName";
  9. Notification.cancelGroup(groupName, cancelGroupCallback);

Notification.cancelGroup

cancelGroup(groupName: string): Promise<void>

取消本應(yīng)用指定組下的通知(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

groupName

string

通知組名稱。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. let groupName = "GroupName";
  2. Notification.cancelGroup(groupName).then(() => {
  3. console.info("cancelGroup success");
  4. });

Notification.isSupportTemplate

isSupportTemplate(templateName: string, callback: AsyncCallback<boolean>): void

查詢模板是否存在(Callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

templateName

string

模板名稱。

callback

AsyncCallback<boolean>

查詢模板是否存在的回調(diào)函數(shù)。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

1600011

Read template config failed.

示例:

  1. let templateName = 'process';
  2. function isSupportTemplateCallback(err, data) {
  3. if (err) {
  4. console.info("isSupportTemplate failed " + JSON.stringify(err));
  5. } else {
  6. console.info("isSupportTemplate success");
  7. }
  8. }
  9. Notification.isSupportTemplate(templateName, isSupportTemplateCallback);

Notification.isSupportTemplate

isSupportTemplate(templateName: string): Promise<boolean>

查詢模板是否存在(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

templateName

string

模板名稱。

返回值:

類型

說明

Promise<boolean>

Promise方式返回模板是否存在的結(jié)果。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

1600011

Read template config failed.

示例:

  1. let templateName = 'process';
  2. Notification.isSupportTemplate(templateName).then((data) => {
  3. console.info("isSupportTemplate success, data: " + JSON.stringify(data));
  4. });

Notification.requestEnableNotification

requestEnableNotification(callback: AsyncCallback<void>): void

應(yīng)用請求通知使能(Callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<void>

應(yīng)用請求通知使能的回調(diào)函數(shù)。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. function requestEnableNotificationCallback(err) {
  2. if (err) {
  3. console.info("requestEnableNotification failed " + JSON.stringify(err));
  4. } else {
  5. console.info("requestEnableNotification success");
  6. }
  7. };
  8. Notification.requestEnableNotification(requestEnableNotificationCallback);

Notification.requestEnableNotification

requestEnableNotification(): Promise<void>

應(yīng)用請求通知使能(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

示例:

  1. Notification.requestEnableNotification().then(() => {
  2. console.info("requestEnableNotification success");
  3. });

Notification.isDistributedEnabled

isDistributedEnabled(callback: AsyncCallback<boolean>): void

查詢設(shè)備是否支持分布式通知(Callback形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<boolean>

設(shè)備是否支持分布式通知的回調(diào)函數(shù)。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification。

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

1600010

Distributed operation failed.

示例:

  1. function isDistributedEnabledCallback(err, data) {
  2. if (err) {
  3. console.info("isDistributedEnabled failed " + JSON.stringify(err));
  4. } else {
  5. console.info("isDistributedEnabled success " + JSON.stringify(data));
  6. }
  7. };
  8. Notification.isDistributedEnabled(isDistributedEnabledCallback);

Notification.isDistributedEnabled

isDistributedEnabled(): Promise<boolean>

查詢設(shè)備是否支持分布式通知(Promise形式)。

系統(tǒng)能力:SystemCapability.Notification.Notification

返回值:

類型

說明

Promise<boolean>

Promise方式返回設(shè)備是否支持分布式通知的結(jié)果。

錯(cuò)誤碼:

錯(cuò)誤碼詳細(xì)介紹請參考errcode-notification

錯(cuò)誤碼ID

錯(cuò)誤信息

1600001

Internal error.

1600002

Marshalling or unmarshalling error.

1600003

Failed to connect service.

1600010

Distributed operation failed.

示例:

  1. Notification.isDistributedEnabled()
  2. .then((data) => {
  3. console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
  4. });

ContentType

系統(tǒng)能力:以下各項(xiàng)對應(yīng)的系統(tǒng)能力均為SystemCapability.Notification.Notification

名稱

說明

NOTIFICATION_CONTENT_BASIC_TEXT

NOTIFICATION_CONTENT_BASIC_TEXT

普通類型通知。

NOTIFICATION_CONTENT_LONG_TEXT

NOTIFICATION_CONTENT_LONG_TEXT

長文本類型通知。

NOTIFICATION_CONTENT_PICTURE

NOTIFICATION_CONTENT_PICTURE

圖片類型通知。

NOTIFICATION_CONTENT_CONVERSATION

NOTIFICATION_CONTENT_CONVERSATION

社交類型通知。

NOTIFICATION_CONTENT_MULTILINE

NOTIFICATION_CONTENT_MULTILINE

多行文本類型通知。

SlotType

系統(tǒng)能力:以下各項(xiàng)對應(yīng)的系統(tǒng)能力均為SystemCapability.Notification.Notification

名稱

說明

UNKNOWN_TYPE

0

未知類型。

SOCIAL_COMMUNICATION

1

社交類型。

SERVICE_INFORMATION

2

服務(wù)類型。

CONTENT_INFORMATION

3

內(nèi)容類型。

OTHER_TYPES

0xFFFF

其他類型。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號