W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
本模塊提供通知管理的能力,包括發(fā)布、取消發(fā)布通知,創(chuàng)建、獲取、移除通知通道,獲取通知的使能狀態(tài)、角標(biāo)使能狀態(tài),獲取通知的相關(guān)信息等。
本模塊首批接口從API version 9開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。
publish(request: NotificationRequest, callback: AsyncCallback<void>): void
發(fā)布通知(callback形式)。
系統(tǒng)能力:SystemCapability.Notification.Notification
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
request | 是 | 用于設(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. |
示例:
- //publish回調(diào)
- function publishCallback(err) {
- if (err) {
- console.info("publish failed " + JSON.stringify(err));
- } else {
- console.info("publish success");
- }
- }
- //通知Request對象
- let notificationRequest = {
- id: 1,
- content: {
- contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
- normal: {
- title: "test_title",
- text: "test_text",
- additionalText: "test_additionalText"
- }
- }
- };
- Notification.publish(notificationRequest, publishCallback);
publish(request: NotificationRequest): Promise<void>
發(fā)布通知(Promise形式)。
系統(tǒng)能力:SystemCapability.Notification.Notification
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
request | 是 | 用于設(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. |
示例:
- // 通知Request對象
- let notificationRequest = {
- notificationId: 1,
- content: {
- contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
- normal: {
- title: "test_title",
- text: "test_text",
- additionalText: "test_additionalText"
- }
- }
- };
- Notification.publish(notificationRequest).then(() => {
- console.info("publish success");
- });
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. |
示例:
- // cancel回調(diào)
- function cancelCallback(err) {
- if (err) {
- console.info("cancel failed " + JSON.stringify(err));
- } else {
- console.info("cancel success");
- }
- }
- Notification.cancel(0, "label", cancelCallback);
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. |
示例:
- Notification.cancel(0).then(() => {
- console.info("cancel success");
- });
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. |
示例:
- // cancel回調(diào)
- function cancelCallback(err) {
- if (err) {
- console.info("cancel failed " + JSON.stringify(err));
- } else {
- console.info("cancel success");
- }
- }
- Notification.cancel(0, cancelCallback);
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)方法。 |
示例:
- // cancel回調(diào)
- function cancelAllCallback(err) {
- if (err) {
- console.info("cancelAll failed " + JSON.stringify(err));
- } else {
- console.info("cancelAll success");
- }
- }
- Notification.cancelAll(cancelAllCallback);
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. |
示例:
- Notification.cancelAll().then(() => {
- console.info("cancelAll success");
- });
addSlot(type: SlotType, callback: AsyncCallback<void>): void
創(chuàng)建指定類型的通知通道(callback形式)。
系統(tǒng)能力:SystemCapability.Notification.Notification
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | 是 | 要?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. |
示例:
- // addslot回調(diào)
- function addSlotCallBack(err) {
- if (err) {
- console.info("addSlot failed " + JSON.stringify(err));
- } else {
- console.info("addSlot success");
- }
- }
- Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack);
addSlot(type: SlotType): Promise<void>
創(chuàng)建指定類型的通知通道(Promise形式)。
系統(tǒng)能力:SystemCapability.Notification.Notification
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | 是 | 要?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. |
示例:
- Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
- console.info("addSlot success");
- });
getSlot(slotType: SlotType, callback: AsyncCallback<NotificationSlot>): void
獲取一個(gè)指定類型的通知通道(callback形式)。
系統(tǒng)能力:SystemCapability.Notification.Notification
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
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. |
示例:
- // getSlot回調(diào)
- function getSlotCallback(err,data) {
- if (err) {
- console.info("getSlot failed " + JSON.stringify(err));
- } else {
- console.info("getSlot success");
- }
- }
- let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
- Notification.getSlot(slotType, getSlotCallback);
getSlot(slotType: SlotType): Promise<NotificationSlot>
獲取一個(gè)指定類型的通知通道(Promise形式)。
系統(tǒng)能力:SystemCapability.Notification.Notification
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
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. |
示例:
- let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
- Notification.getSlot(slotType).then((data) => {
- console.info("getSlot success, data: " + JSON.stringify(data));
- });
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. |
示例:
- // getSlots回調(diào)
- function getSlotsCallback(err,data) {
- if (err) {
- console.info("getSlots failed " + JSON.stringify(err));
- } else {
- console.info("getSlots success");
- }
- }
- Notification.getSlots(getSlotsCallback);
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. |
示例:
- Notification.getSlots().then((data) => {
- console.info("getSlots success, data: " + JSON.stringify(data));
- });
removeSlot(slotType: SlotType, callback: AsyncCallback<void>): void
刪除指定類型的通知通道(callback形式)。
系統(tǒng)能力:SystemCapability.Notification.Notification
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
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. |
示例:
- // removeSlot回調(diào)
- function removeSlotCallback(err) {
- if (err) {
- console.info("removeSlot failed " + JSON.stringify(err));
- } else {
- console.info("removeSlot success");
- }
- }
- let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
- Notification.removeSlot(slotType,removeSlotCallback);
removeSlot(slotType: SlotType): Promise<void>
刪除指定類型的通知通道(Promise形式)。
系統(tǒng)能力:SystemCapability.Notification.Notification
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
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. |
示例:
- let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
- Notification.removeSlot(slotType).then(() => {
- console.info("removeSlot success");
- });
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. |
示例:
- function removeAllCallBack(err) {
- if (err) {
- console.info("removeAllSlots failed " + JSON.stringify(err));
- } else {
- console.info("removeAllSlots success");
- }
- }
- Notification.removeAllSlots(removeAllCallBack);
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. |
示例:
- Notification.removeAllSlots().then(() => {
- console.info("removeAllSlots success");
- });
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. |
示例:
- function getActiveNotificationCountCallback(err, data) {
- if (err) {
- console.info("getActiveNotificationCount failed " + JSON.stringify(err));
- } else {
- console.info("getActiveNotificationCount success");
- }
- }
- Notification.getActiveNotificationCount(getActiveNotificationCountCallback);
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. |
示例:
- Notification.getActiveNotificationCount().then((data) => {
- console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
- });
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. |
示例:
- function getActiveNotificationsCallback(err, data) {
- if (err) {
- console.info("getActiveNotifications failed " + JSON.stringify(err));
- } else {
- console.info("getActiveNotifications success");
- }
- }
- Notification.getActiveNotifications(getActiveNotificationsCallback);
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. |
示例:
- Notification.getActiveNotifications().then((data) => {
- console.info("removeGroupByBundle success, data: " + JSON.stringify(data));
- });
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. |
示例:
- function cancelGroupCallback(err) {
- if (err) {
- console.info("cancelGroup failed " + JSON.stringify(err));
- } else {
- console.info("cancelGroup success");
- }
- }
- let groupName = "GroupName";
- Notification.cancelGroup(groupName, cancelGroupCallback);
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. |
示例:
- let groupName = "GroupName";
- Notification.cancelGroup(groupName).then(() => {
- console.info("cancelGroup success");
- });
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. |
示例:
- let templateName = 'process';
- function isSupportTemplateCallback(err, data) {
- if (err) {
- console.info("isSupportTemplate failed " + JSON.stringify(err));
- } else {
- console.info("isSupportTemplate success");
- }
- }
- Notification.isSupportTemplate(templateName, isSupportTemplateCallback);
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. |
示例:
- let templateName = 'process';
- Notification.isSupportTemplate(templateName).then((data) => {
- console.info("isSupportTemplate success, data: " + JSON.stringify(data));
- });
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. |
示例:
- function requestEnableNotificationCallback(err) {
- if (err) {
- console.info("requestEnableNotification failed " + JSON.stringify(err));
- } else {
- console.info("requestEnableNotification success");
- }
- };
- Notification.requestEnableNotification(requestEnableNotificationCallback);
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. |
示例:
- Notification.requestEnableNotification().then(() => {
- console.info("requestEnableNotification success");
- });
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. |
示例:
- function isDistributedEnabledCallback(err, data) {
- if (err) {
- console.info("isDistributedEnabled failed " + JSON.stringify(err));
- } else {
- console.info("isDistributedEnabled success " + JSON.stringify(data));
- }
- };
- Notification.isDistributedEnabled(isDistributedEnabledCallback);
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. |
示例:
- Notification.isDistributedEnabled()
- .then((data) => {
- console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
- });
系統(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 | 多行文本類型通知。 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: