@capacitor/local-notifications
本地通知 API 提供了一種在本地排程裝置通知的方式(即無需伺服器發送推播通知)。
安裝
npm install @capacitor/local-notifications
npx cap sync
Android
Android 13 需要權限檢查才能發送通知。您需要相應地呼叫 checkPermissions()
和 requestPermissions()
。
在 Android 12 和更早版本上,它不會顯示提示,而只會返回已授權。
從 Android 12 開始,除非將此權限新增至您的 AndroidManifest.xml
,否則排定的通知將不會精確。
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
請注意,即使存在此權限,使用者仍然可以從應用程式設定中停用精確通知。使用 checkExactNotificationSetting()
檢查設定的值。如果使用者停用此設定,應用程式將會重新啟動,任何使用精確鬧鐘排定的通知都將被刪除。如果您的應用程式依賴精確鬧鐘,請務必在應用程式啟動時(例如,在 App.appStateChange
中)檢查此設定,以便提供備用或替代行為。
在 Android 14 上,有一個新的權限稱為 USE_EXACT_ALARM
。使用此權限可以在不需要使用者請求權限的情況下使用精確鬧鐘。只有在精確鬧鐘的使用對於您的應用程式功能至關重要時,才應該使用此權限。請在此處閱讀更多關於使用此權限的含義。
設定
在 Android 上,可以使用以下選項設定本地通知
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
smallIcon | 字串 | 設定通知的預設狀態列圖示。圖示應放置在您應用程式的 res/drawable 資料夾中。此選項的值應為可繪製資源 ID,也就是不含副檔名的檔案名稱。僅適用於 Android。 | 1.0.0 |
iconColor | 字串 | 設定通知的預設狀態列圖示顏色。僅適用於 Android。 | 1.0.0 |
sound | 字串 | 設定通知的預設通知音效。在 Android 26+ 上,它會設定預設頻道音效,除非卸載應用程式,否則無法變更。如果找不到音訊檔案,則在 Android 21-25 上會播放預設系統音效,在 Android 26+ 上則不會播放音效。僅適用於 Android。 | 1.0.0 |
範例
在 capacitor.config.json
中
{
"plugins": {
"LocalNotifications": {
"smallIcon": "ic_stat_icon_config_sample",
"iconColor": "#488AFF",
"sound": "beep.wav"
}
}
}
在 capacitor.config.ts
中
/// <reference types="@capacitor/local-notifications" />
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
plugins: {
LocalNotifications: {
smallIcon: "ic_stat_icon_config_sample",
iconColor: "#488AFF",
sound: "beep.wav",
},
},
};
export default config;
Doze
如果裝置已進入 Doze 模式,您的應用程式可能會受到限制。如果您需要在 Doze 期間觸發通知,請使用 allowWhileIdle: true
排程您的通知。請謹慎使用 allowWhileIdle
,因為這些通知每個應用程式每 9 分鐘只能觸發一次。
API
schedule(...)
getPending()
registerActionTypes(...)
cancel(...)
areEnabled()
getDeliveredNotifications()
removeDeliveredNotifications(...)
removeAllDeliveredNotifications()
createChannel(...)
deleteChannel(...)
listChannels()
checkPermissions()
requestPermissions()
changeExactNotificationSetting()
checkExactNotificationSetting()
addListener('localNotificationReceived', ...)
addListener('localNotificationActionPerformed', ...)
removeAllListeners()
- 介面
- 類型別名
- 列舉
schedule(...)
schedule(options: ScheduleOptions) => Promise<ScheduleResult>
排程一個或多個本地通知。
參數 | 類型 |
---|---|
options | ScheduleOptions |
傳回:Promise<ScheduleResult>
自 1.0.0
getPending()
getPending() => Promise<PendingResult>
取得待處理通知的清單。
傳回:Promise<PendingResult>
自 1.0.0
registerActionTypes(...)
registerActionTypes(options: RegisterActionTypesOptions) => Promise<void>
註冊顯示通知時要採取的動作。
僅適用於 iOS 和 Android。
參數 | 類型 |
---|---|
options | RegisterActionTypesOptions |
自 1.0.0
cancel(...)
cancel(options: CancelOptions) => Promise<void>
取消待處理通知。
參數 | 類型 |
---|---|
options | CancelOptions |
自 1.0.0
areEnabled()
areEnabled() => Promise<EnabledResult>
檢查是否啟用通知。
傳回:Promise<EnabledResult>
自 1.0.0
getDeliveredNotifications()
getDeliveredNotifications() => Promise<DeliveredNotifications>
取得在通知畫面中可見的通知清單。
傳回:Promise<DeliveredNotifications>
自 4.0.0
removeDeliveredNotifications(...)
removeDeliveredNotifications(delivered: DeliveredNotifications) => Promise<void>
從通知畫面移除指定的通知。
參數 | 類型 |
---|---|
delivered | DeliveredNotifications |
自 4.0.0
removeAllDeliveredNotifications()
removeAllDeliveredNotifications() => Promise<void>
從通知畫面移除所有通知。
自 4.0.0
createChannel(...)
createChannel(channel: Channel) => Promise<void>
建立通知頻道。
僅適用於 Android。
參數 | 類型 |
---|---|
channel | Channel |
自 1.0.0
deleteChannel(...)
deleteChannel(args: { id: string; }) => Promise<void>
刪除通知頻道。
僅適用於 Android。
參數 | 類型 |
---|---|
args | { id: string; } |
自 1.0.0
listChannels()
listChannels() => Promise<ListChannelsResult>
取得通知頻道的清單。
僅適用於 Android。
傳回:Promise<ListChannelsResult>
自 1.0.0
checkPermissions()
checkPermissions() => Promise<PermissionStatus>
檢查是否具有顯示本地通知的權限。
傳回:Promise<PermissionStatus>
自 1.0.0
requestPermissions()
requestPermissions() => Promise<PermissionStatus>
請求顯示本地通知的權限。
傳回:Promise<PermissionStatus>
自 1.0.0
changeExactNotificationSetting()
changeExactNotificationSetting() => Promise<SettingsPermissionStatus>
將使用者導向應用程式設定畫面,以設定精確鬧鐘。
如果使用者將設定從已授權變更為已拒絕,應用程式將會重新啟動,並且任何使用精確鬧鐘排程的通知都將被刪除。
在 Android < 12 上,使用者不會被導向應用程式設定畫面,相反地,此函式將傳回 granted
。
僅適用於 Android。
傳回:Promise<SettingsPermissionStatus>
自 6.0.0
checkExactNotificationSetting()
checkExactNotificationSetting() => Promise<SettingsPermissionStatus>
檢查應用程式設定以使用精確鬧鐘。
僅適用於 Android。
傳回:Promise<SettingsPermissionStatus>
自 6.0.0
addListener('localNotificationReceived', ...)
addListener(eventName: 'localNotificationReceived', listenerFunc: (notification: LocalNotificationSchema) => void) => Promise<PluginListenerHandle>
監聽何時顯示通知。
參數 | 類型 |
---|---|
eventName | 'localNotificationReceived' |
listenerFunc | (notification: LocalNotificationSchema) => void |
傳回:Promise<PluginListenerHandle>
自 1.0.0
addListener('localNotificationActionPerformed', ...)
addListener(eventName: 'localNotificationActionPerformed', listenerFunc: (notificationAction: ActionPerformed) => void) => Promise<PluginListenerHandle>
監聽在通知上執行動作的時間。
參數 | 類型 |
---|---|
eventName | 'localNotificationActionPerformed' |
listenerFunc | (notificationAction: ActionPerformed) => void |
傳回:Promise<PluginListenerHandle>
自 1.0.0
removeAllListeners()
removeAllListeners() => Promise<void>
移除此外掛程式的所有監聽器。
自 1.0.0
介面
ScheduleResult
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
notifications | LocalNotificationDescriptor[] | 排程通知的列表。 | 1.0.0 |
LocalNotificationDescriptor
描述本地通知的物件。
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
id | number | 通知識別碼。 | 1.0.0 |
ScheduleOptions
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
notifications | LocalNotificationSchema[] | 要排程的通知列表。 | 1.0.0 |
LocalNotificationSchema
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
title | 字串 | 通知的標題。 | 1.0.0 |
body | 字串 | 通知的內容,顯示在標題下方。 | 1.0.0 |
largeBody | 字串 | 設定在大型文字通知樣式中顯示的多行文字區塊。 | 1.0.0 |
summaryText | 字串 | 用於在收件匣和大型文字通知樣式中設定摘要文字詳細資訊。僅適用於 Android。 | 1.0.0 |
id | number | 通知識別碼。在 Android 上,它是一個 32 位元的整數。因此,該值應該介於 -2147483648 和 2147483647 之間(包含)。 | 1.0.0 |
schedule | Schedule | 排程此通知以供稍後顯示。 | 1.0.0 |
sound | 字串 | 顯示此通知時播放的音訊檔案名稱。請包含檔案名稱的副檔名。在 iOS 上,該檔案應位於應用程式套件中。在 Android 上,該檔案應位於 res/raw 資料夾中。建議的格式為 .wav ,因為 iOS 和 Android 都支援此格式。僅適用於 iOS 和 Android < 26。對於 Android 26+,請使用配置了所需聲音的頻道 ID。如果找不到聲音檔案(即,空字串或錯誤的名稱),則會使用預設的系統通知聲音。如果未提供,則會在 Android 上產生預設聲音,在 iOS 上則不會產生聲音。 | 1.0.0 |
smallIcon | 字串 | 設定自訂狀態列圖示。如果設定,則會覆寫 Capacitor 設定中的 smallIcon 選項。圖示應放置在應用程式的 res/drawable 資料夾中。此選項的值應為可繪製資源 ID,即不含副檔名的檔案名稱。僅適用於 Android。 | 1.0.0 |
largeIcon | 字串 | 設定通知的大型圖示。圖示應放置在應用程式的 res/drawable 資料夾中。此選項的值應為可繪製資源 ID,即不含副檔名的檔案名稱。僅適用於 Android。 | 1.0.0 |
iconColor | 字串 | 設定通知圖示的顏色。僅適用於 Android。 | 1.0.0 |
attachments | Attachment[] | 為此通知設定附件。 | 1.0.0 |
actionTypeId | 字串 | 將動作類型與此通知關聯。 | 1.0.0 |
extra | any | 設定要在此通知中儲存的額外資料。 | 1.0.0 |
threadIdentifier | 字串 | 用於群組多個通知。在 UNMutableNotificationContent 上設定 threadIdentifier 。僅適用於 iOS。 | 1.0.0 |
summaryArgument | 字串 | 此通知新增至類別摘要格式字串的字串。在 UNMutableNotificationContent 上設定 summaryArgument 。僅適用於 iOS。 | 1.0.0 |
group | 字串 | 用於群組多個通知。使用提供的值在 NotificationCompat.Builder 上呼叫 setGroup() 。僅適用於 Android。 | 1.0.0 |
groupSummary | boolean | 如果為 true,則此通知會成為一組通知的摘要。使用提供的值在 NotificationCompat.Builder 上呼叫 setGroupSummary() 。僅在使用 group 時適用於 Android。 | 1.0.0 |
channelId | 字串 | 指定應在哪个頻道上傳遞通知。如果不存在具有指定名稱的頻道,則通知將不會觸發。如果未提供,則會使用預設頻道。使用提供的值在 NotificationCompat.Builder 上呼叫 setChannelId() 。僅適用於 Android 26+。 | 1.0.0 |
ongoing | boolean | 如果為 true,則無法滑動關閉通知。使用提供的值在 NotificationCompat.Builder 上呼叫 setOngoing() 。僅適用於 Android。 | 1.0.0 |
autoCancel | boolean | 如果為 true,則當使用者點擊通知時會取消通知。使用提供的值在 NotificationCompat.Builder 上呼叫 setAutoCancel() 。僅適用於 Android。 | 1.0.0 |
inboxList | string[] | 設定要在收件匣樣式通知中顯示的字串列表。最多允許 5 個字串。僅適用於 Android。 | 1.0.0 |
silent | boolean | 如果為 true,則在應用程式處於前景時通知不會出現。僅適用於 iOS。 | 5.0.0 |
Schedule
表示通知的排程。
使用 at
、on
或 every
來排程通知。
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
at | Date | 在特定日期和時間排程通知。 | 1.0.0 |
repeats | boolean | 在 at 指定的日期和時間重複傳遞此通知。僅適用於 iOS 和 Android。 | 1.0.0 |
allowWhileIdle | boolean | 允許此通知在 Doze 模式下觸發。僅適用於 Android 23+。請注意,這些通知只能在每個應用程式每 9 分鐘觸發一次。 | 1.0.0 |
on | ScheduleOn | 在特定的間隔排程通知。這類似於排程 cron 工作。僅適用於 iOS 和 Android。 | 1.0.0 |
every | ScheduleEvery | 以特定間隔排程通知。 | 1.0.0 |
count | number | 限制 every 指定的間隔傳遞通知的次數。 | 1.0.0 |
Date
啟用日期和時間的基本儲存和擷取。
Method | Signature | 描述 |
---|---|---|
toString | () => string | 傳回日期字串表示。字串的格式取決於地區設定。 |
toDateString | () => string | 傳回日期字串值。 |
toTimeString | () => string | 傳回時間字串值。 |
toLocaleString | () => string | 傳回符合主機環境目前地區設定的字串值。 |
toLocaleDateString | () => string | 傳回符合主機環境目前地區設定的日期字串值。 |
toLocaleTimeString | () => string | 傳回符合主機環境目前地區設定的時間字串值。 |
valueOf | () => number | 傳回自 1970 年 1 月 1 日午夜 (UTC) 以來的儲存時間值(以毫秒為單位)。 |
getTime | () => number | 取得時間值(以毫秒為單位)。 |
getFullYear | () => number | 使用本地時間取得年份。 |
getUTCFullYear | () => number | 使用世界協調時間 (UTC) 取得年份。 |
getMonth | () => number | 使用本地時間取得月份。 |
getUTCMonth | () => number | 使用世界協調時間 (UTC) 取得 Date 物件的月份。 |
getDate | () => number | 使用本地時間取得月份中的日期。 |
getUTCDate | () => number | 使用世界協調時間 (UTC) 取得月份中的日期。 |
getDay | () => number | 使用本地時間取得星期幾。 |
getUTCDay | () => number | 使用世界協調時間 (UTC) 取得星期幾。 |
getHours | () => number | 使用本地時間取得日期中的小時。 |
getUTCHours | () => number | 使用世界協調時間 (UTC) 取得 Date 物件中的小時值。 |
getMinutes | () => number | 使用本地時間取得 Date 物件的分鐘。 |
getUTCMinutes | () => number | 使用世界協調時間 (UTC) 取得 Date 物件的分鐘。 |
getSeconds | () => number | 使用本地時間取得 Date 物件的秒數。 |
getUTCSeconds | () => number | 使用世界協調時間 (UTC) 取得 Date 物件的秒數。 |
getMilliseconds | () => number | 使用本地時間取得 Date 的毫秒。 |
getUTCMilliseconds | () => number | 使用世界協調時間 (UTC) 取得 Date 物件的毫秒。 |
getTimezoneOffset | () => number | 取得本機電腦上的時間與世界協調時間 (UTC) 之間的分鐘差異。 |
setTime | (time: number) => number | 設定 Date 物件中的日期和時間值。 |
setMilliseconds | (ms: number) => number | 使用本地時間設定 Date 物件中的毫秒值。 |
setUTCMilliseconds | (ms: number) => number | 使用世界協調時間 (UTC) 設定 Date 物件中的毫秒值。 |
setSeconds | (sec: number, ms?: number | undefined) => number | 使用本地時間設定 Date 物件中的秒數值。 |
setUTCSeconds | (sec: number, ms?: number | undefined) => number | 使用世界協調時間 (UTC) 設定 Date 物件中的秒數值。 |
setMinutes | (min: number, sec?: number | undefined, ms?: number | undefined) => number | 使用本地時間設定 Date 物件中的分鐘值。 |
setUTCMinutes | (min: number, sec?: number | undefined, ms?: number | undefined) => number | 使用世界協調時間 (UTC) 設定 Date 物件中的分鐘值。 |
setHours | (hours: number, min?: number | undefined, sec?: number | undefined, ms?: number | undefined) => number | 使用本地時間設定 Date 物件中的小時值。 |
setUTCHours | (hours: number, min?: number | undefined, sec?: number | undefined, ms?: number | undefined) => number | 使用世界協調時間 (UTC) 設定 Date 物件中的小時值。 |
setDate | (date: number) => number | 使用本地時間設定 Date 物件的月份中的數值日期。 |
setUTCDate | (date: number) => number | 使用世界協調時間 (UTC) 設定 Date 物件中的月份數值日期。 |
setMonth | (month: number, date?: number | undefined) => number | 使用本地時間設定 Date 物件中的月份值。 |
setUTCMonth | (month: number, date?: number | undefined) => number | 使用世界協調時間 (UTC) 設定 Date 物件中的月份值。 |
setFullYear | (year: number, month?: number | undefined, date?: number | undefined) => number | 使用本地時間設定 Date 物件的年份。 |
setUTCFullYear | (year: number, month?: number | undefined, date?: number | undefined) => number | 使用世界協調時間 (UTC) 設定 Date 物件中的年份值。 |
toUTCString | () => string | 將日期轉換為使用世界協調時間 (UTC) 的字串並回傳。 |
toISOString | () => string | 以 ISO 格式回傳日期字串值。 |
toJSON | (key?: any) => string | 由 JSON.stringify 方法使用,以啟用物件資料的轉換,用於 JavaScript 物件表示法 (JSON) 序列化。 |
排程於
屬性 | 類型 |
---|---|
年 | number |
月 | number |
日 | number |
星期幾 | 星期幾 |
時 | number |
分 | number |
秒 | number |
附件
代表一個通知附件。
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
id | 字串 | 附件識別符。 | 1.0.0 |
網址 | 字串 | 附件的網址。使用 res 方案來參考網路資源,例如 res:///assets/img/icon.png 。也接受 file 網址。 | 1.0.0 |
options | 附件選項 | 附件選項。 | 1.0.0 |
附件選項
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
iosUNNotificationAttachmentOptionsTypeHintKey | 字串 | 在 UNNotificationAttachment 的可雜湊選項中設定 UNNotificationAttachmentOptionsTypeHintKey 鍵。僅適用於 iOS。 | 1.0.0 |
iosUNNotificationAttachmentOptionsThumbnailHiddenKey | 字串 | 在 UNNotificationAttachment 的可雜湊選項中設定 UNNotificationAttachmentOptionsThumbnailHiddenKey 鍵。僅適用於 iOS。 | 1.0.0 |
iosUNNotificationAttachmentOptionsThumbnailClippingRectKey | 字串 | 在 UNNotificationAttachment 的可雜湊選項中設定 UNNotificationAttachmentOptionsThumbnailClippingRectKey 鍵。僅適用於 iOS。 | 1.0.0 |
iosUNNotificationAttachmentOptionsThumbnailTimeKey | 字串 | 在 UNNotificationAttachment 的可雜湊選項中設定 UNNotificationAttachmentOptionsThumbnailTimeKey 鍵。僅適用於 iOS。 | 1.0.0 |
待處理結果
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
notifications | 待處理的本地通知架構[] | 待處理通知的清單。 | 1.0.0 |
待處理的本地通知架構
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
title | 字串 | 通知的標題。 | 1.0.0 |
body | 字串 | 通知的內容,顯示在標題下方。 | 1.0.0 |
id | number | 通知識別碼。 | 1.0.0 |
schedule | Schedule | 排程此通知以供稍後顯示。 | 1.0.0 |
extra | any | 設定要在此通知中儲存的額外資料。 | 1.0.0 |
註冊動作類型選項
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
類型 | 動作類型[] | 要註冊的動作類型清單。 | 1.0.0 |
動作類型
動作的集合。
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
id | 字串 | 動作類型的 ID。在通知中透過 actionTypeId 鍵引用。 | 1.0.0 |
動作 | 動作[] | 與此動作類型相關聯的動作清單。 | 1.0.0 |
iosHiddenPreviewsBodyPlaceholder | 字串 | 設定 UNNotificationCategory 的 hiddenPreviewsBodyPlaceholder 。僅適用於 iOS。 | 1.0.0 |
iosCustomDismissAction | boolean | 在 UNNotificationCategory 的選項中設定 customDismissAction 。僅適用於 iOS。 | 1.0.0 |
iosAllowInCarPlay | boolean | 在 UNNotificationCategory 的選項中設定 allowInCarPlay 。僅適用於 iOS。 | 1.0.0 |
iosHiddenPreviewsShowTitle | boolean | 在 UNNotificationCategory 的選項中設定 hiddenPreviewsShowTitle 。僅適用於 iOS。 | 1.0.0 |
iosHiddenPreviewsShowSubtitle | boolean | 在 UNNotificationCategory 的選項中設定 hiddenPreviewsShowSubtitle 。僅適用於 iOS。 | 1.0.0 |
動作
當顯示通知時可以採取的動作。
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
id | 字串 | 動作識別符。在 'actionPerformed' 事件中以 actionId 引用。 | 1.0.0 |
title | 字串 | 要為此動作顯示的標題文字。 | 1.0.0 |
需要驗證 | boolean | 在 UNNotificationAction 的選項中設定 authenticationRequired 。僅適用於 iOS。 | 1.0.0 |
前景 | boolean | 在 UNNotificationAction 的選項中設定 foreground 。僅適用於 iOS。 | 1.0.0 |
破壞性 | boolean | 在 UNNotificationAction 的選項中設定 destructive 。僅適用於 iOS。 | 1.0.0 |
輸入 | boolean | 使用 UNTextInputNotificationAction 而不是 UNNotificationAction 。僅適用於 iOS。 | 1.0.0 |
輸入按鈕標題 | 字串 | 在 UNTextInputNotificationAction 上設定 textInputButtonTitle 。僅當 input 為 true 時適用於 iOS。 | 1.0.0 |
輸入預留位置 | 字串 | 在 UNTextInputNotificationAction 上設定 textInputPlaceholder 。僅當 input 為 true 時適用於 iOS。 | 1.0.0 |
取消選項
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
notifications | LocalNotificationDescriptor[] | 要取消的通知清單。 | 1.0.0 |
已啟用結果
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
值 | boolean | 裝置是否已啟用本地通知。 | 1.0.0 |
已傳送的通知
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
notifications | 已傳送的通知架構[] | 通知畫面中可見的通知清單。 | 1.0.0 |
已傳送的通知架構
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
id | number | 通知識別碼。 | 4.0.0 |
標籤 | 字串 | 通知標籤。僅適用於 Android。 | 4.0.0 |
title | 字串 | 通知的標題。 | 4.0.0 |
body | 字串 | 通知的內容,顯示在標題下方。 | 4.0.0 |
group | 字串 | 通知的已設定群組。僅適用於 Android。 | 4.0.0 |
groupSummary | boolean | 此通知是否為通知群組的摘要。僅適用於 Android。 | 4.0.0 |
資料 | any | 通知承載中包含的任何額外資料。僅適用於 Android。 | 4.0.0 |
extra | any | 要儲存在此通知中的額外資料。僅適用於 iOS。 | 4.0.0 |
attachments | Attachment[] | 此通知的附件。僅適用於 iOS。 | 1.0.0 |
actionTypeId | 字串 | 與此通知相關聯的動作類型。僅適用於 iOS。 | 4.0.0 |
schedule | Schedule | 用於觸發此通知的排程。僅適用於 iOS。 | 4.0.0 |
sound | 字串 | 顯示通知時使用的聲音。僅適用於 iOS。 | 4.0.0 |
頻道
屬性 | 類型 | 描述 | 預設 | 自 |
---|---|---|---|---|
id | 字串 | 頻道識別符。 | 1.0.0 | |
名稱 | 字串 | 此頻道的人性化名稱 (呈現給使用者)。 | 1.0.0 | |
描述 | 字串 | 此頻道的描述 (呈現給使用者)。 | 1.0.0 | |
sound | 字串 | 應為發佈至此頻道的通知播放的聲音。重要性至少為 3 的通知頻道應具有聲音。聲音檔案的檔名應相對於 Android 應用程式 res/raw 目錄指定。如果未提供聲音,或找不到聲音檔案,則不會使用聲音。 | 1.0.0 | |
重要性 | 重要性 | 發佈至此頻道的通知的中斷等級。 |
| 1.0.0 |
可見性 | 可見性 | 發佈至此頻道的通知的可見性。此設定用於決定發佈至此頻道的通知是否顯示在鎖定畫面上,如果是,是否以編輯形式顯示。 | 1.0.0 | |
燈光 | boolean | 發佈至此頻道的通知是否應在支援的裝置上顯示通知燈光。 | 1.0.0 | |
燈光顏色 | 字串 | 發佈至此頻道的通知的燈光顏色。僅在啟用此頻道上的燈光且裝置支援時才支援。支援的顏色格式為 #RRGGBB 和 #RRGGBBAA 。 | 1.0.0 | |
震動 | boolean | 發佈至此頻道的通知是否應震動。 | 1.0.0 |
頻道清單結果
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
頻道 | 頻道[] | 通知頻道清單。 | 1.0.0 |
權限狀態
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
顯示 | 權限狀態 | 顯示通知的權限狀態。 | 1.0.0 |
設定權限狀態
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
確切鬧鐘 | 權限狀態 | 使用確切鬧鐘的權限狀態。 | 6.0.0 |
外掛程式監聽器處理
屬性 | 類型 |
---|---|
移除 | () => Promise<void> |
已執行的動作
屬性 | 類型 | 描述 | 自 |
---|---|---|---|
actionId | 字串 | 已執行動作的識別符。 | 1.0.0 |
輸入值 | 字串 | 使用者在通知中輸入的值。僅當通知的 input 設定為 true 時適用於 iOS。 | 1.0.0 |
通知 | 本地通知架構 | 原始通知架構。 | 1.0.0 |
類型別名
排程間隔
'year' | 'month' | 'two-weeks' | 'week' | 'day' | 'hour' | 'minute' | 'second'
重要性
重要性等級。如需更多詳細資訊,請參閱 Android 開發人員文件
1 | 2 | 3 | 4 | 5
可見性
通知可見性。如需更多詳細資訊,請參閱 Android 開發人員文件
-1 | 0 | 1
PermissionState
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
列舉 (Enums)
Weekday
成員 | 值 |
---|---|
星期日 | 1 |
星期一 | 2 |
星期二 | 3 |
星期三 | 4 |
星期四 | 5 |
星期五 | 6 |
星期六 | 7 |