UNPKG

capacitor-notification-reader

Version:

Capacitor plugin to read and persist Android notifications with RoomDB storage

1,101 lines 31.8 kB
{ "api": { "name": "NotificationReaderPlugin", "slug": "notificationreaderplugin", "docs": "", "tags": [], "methods": [ { "name": "getActiveNotifications", "signature": "() => Promise<GetActiveNotificationsResult>", "parameters": [], "returns": "Promise<GetActiveNotificationsResult>", "tags": [ { "name": "returns", "text": "Promise resolving with the list of active notifications" }, { "name": "throws", "text": "Error if notification listener service is not connected or permission is not granted" }, { "name": "since", "text": "1.0.0" }, { "name": "platform", "text": "Android" } ], "docs": "Gets all active notifications from the notification listener service.", "complexTypes": [ "GetActiveNotificationsResult" ], "slug": "getactivenotifications" }, { "name": "openAccessSettings", "signature": "() => Promise<{ enabled: boolean; }>", "parameters": [], "returns": "Promise<{ enabled: boolean; }>", "tags": [ { "name": "returns", "text": "Promise resolving with an object indicating if permission was granted" }, { "name": "throws", "text": "Error if unable to open settings" }, { "name": "since", "text": "1.0.0" }, { "name": "platform", "text": "Android" } ], "docs": "Opens the system settings page to allow the user to grant notification access\nto the app. The promise resolves when the user returns from settings with\nthe current permission status.", "complexTypes": [], "slug": "openaccesssettings" }, { "name": "isAccessEnabled", "signature": "() => Promise<{ enabled: boolean; }>", "parameters": [], "returns": "Promise<{ enabled: boolean; }>", "tags": [ { "name": "returns", "text": "Promise resolving with an object indicating if access is enabled" }, { "name": "since", "text": "1.0.0" }, { "name": "platform", "text": "Android" } ], "docs": "Checks if the app has notification access enabled.", "complexTypes": [], "slug": "isaccessenabled" }, { "name": "getNotifications", "signature": "(options?: GetNotificationsOptions | undefined) => Promise<GetNotificationsResult>", "parameters": [ { "name": "options", "docs": "- Cursor, limit, and filtering options", "type": "GetNotificationsOptions | undefined" } ], "returns": "Promise<GetNotificationsResult>", "tags": [ { "name": "param", "text": "options - Cursor, limit, and filtering options" }, { "name": "returns", "text": "Promise resolving with the list of notifications from the database" }, { "name": "since", "text": "1.0.0" }, { "name": "platform", "text": "Android" } ], "docs": "Retrieves notifications from the persistent Room database with optional\nfiltering and cursor-based pagination. Notifications are cached when they are posted and can be\nqueried later even after dismissal from the notification drawer.", "complexTypes": [ "GetNotificationsResult", "GetNotificationsOptions" ], "slug": "getnotifications" }, { "name": "deleteAllNotifications", "signature": "() => Promise<void>", "parameters": [], "returns": "Promise<void>", "tags": [ { "name": "returns", "text": "Promise resolving when all notifications have been deleted" }, { "name": "since", "text": "1.0.0" }, { "name": "platform", "text": "Android" } ], "docs": "Deletes all notifications from the database.\nThis does not affect notifications in the system notification drawer.", "complexTypes": [], "slug": "deleteallnotifications" }, { "name": "getTotalCount", "signature": "() => Promise<{ count: number; }>", "parameters": [], "returns": "Promise<{ count: number; }>", "tags": [ { "name": "returns", "text": "Promise resolving with an object containing the total count" }, { "name": "since", "text": "1.0.0" }, { "name": "platform", "text": "Android" } ], "docs": "Gets the total count of notifications stored in the database.\nThis count includes all notifications regardless of their status or type.", "complexTypes": [], "slug": "gettotalcount" }, { "name": "importNotifications", "signature": "(options: ImportNotificationsOptions) => Promise<void>", "parameters": [ { "name": "options", "docs": "- Object containing the array of notifications to import", "type": "ImportNotificationsOptions" } ], "returns": "Promise<void>", "tags": [ { "name": "param", "text": "options - Object containing the array of notifications to import" }, { "name": "returns", "text": "Promise resolving when all notifications have been imported" }, { "name": "throws", "text": "Error if the notifications array is missing or if an error occurs during import" }, { "name": "since", "text": "1.0.0" }, { "name": "platform", "text": "Android" }, { "name": "example", "text": "```typescript\nconst notificationsToImport = [\n {\n id: 'notification-1',\n appName: 'Example App',\n packageName: 'com.example.app',\n title: 'Test Notification',\n text: 'This is a test',\n timestamp: Date.now(),\n style: NotificationStyle.DEFAULT,\n actions: [],\n isGroupSummary: false,\n isOngoing: false,\n autoCancel: true,\n isLocalOnly: false,\n priority: 0,\n number: 0\n }\n];\n\nawait NotificationReader.importNotifications({\n notifications: notificationsToImport\n});\n```" } ], "docs": "Imports an array of notifications into the database.\nThis method is useful for restoring previously exported notifications,\nmigrating data from another source, or bulk-importing notification data.\n\nEach notification will be inserted using REPLACE strategy, meaning if a\nnotification with the same ID already exists, it will be updated.", "complexTypes": [ "ImportNotificationsOptions" ], "slug": "importnotifications" }, { "name": "getInstalledApps", "signature": "() => Promise<GetInstalledAppsResult>", "parameters": [], "returns": "Promise<GetInstalledAppsResult>", "tags": [ { "name": "returns", "text": "Promise resolving with the list of installed apps" }, { "name": "since", "text": "1.0.0" }, { "name": "platform", "text": "Android" }, { "name": "example", "text": "```typescript\nconst { apps } = await NotificationReader.getInstalledApps();\nconst userApps = apps.filter(app => !app.isSystemApp);\nconsole.log('User apps:', userApps.map(app => app.appName));\n```" } ], "docs": "Retrieves a list of all installed applications on the device.\nReturns app name, package name, app icon, and whether it's a system app.", "complexTypes": [ "GetInstalledAppsResult" ], "slug": "getinstalledapps" }, { "name": "addListener", "signature": "(eventName: 'notificationPosted', listenerFunc: (notification: NotificationItem) => void) => Promise<PluginListenerHandle>", "parameters": [ { "name": "eventName", "docs": "", "type": "'notificationPosted'" }, { "name": "listenerFunc", "docs": "", "type": "(notification: NotificationItem) => void" } ], "returns": "Promise<PluginListenerHandle>", "tags": [], "docs": "Listen for notifications that are posted while the listener service is running.\nFires with the freshly-captured notification payload.", "complexTypes": [ "PluginListenerHandle", "NotificationItem" ], "slug": "addlistenernotificationposted-" } ], "properties": [] }, "interfaces": [ { "name": "GetActiveNotificationsResult", "slug": "getactivenotificationsresult", "docs": "Result returned by getActiveNotifications.", "tags": [], "methods": [], "properties": [ { "name": "notifications", "tags": [], "docs": "Array of active notifications with type-specific shapes.", "complexTypes": [ "NotificationItem" ], "type": "NotificationItem[]" } ] }, { "name": "BigTextNotification", "slug": "bigtextnotification", "docs": "Big text style notification with expanded text content", "tags": [], "methods": [], "properties": [ { "name": "style", "tags": [], "docs": "Notification style template used", "complexTypes": [ "NotificationStyle" ], "type": "NotificationStyle.BIG_TEXT" }, { "name": "bigText", "tags": [], "docs": "The full expanded text content", "complexTypes": [], "type": "string | undefined" } ] }, { "name": "BigPictureNotification", "slug": "bigpicturenotification", "docs": "Big picture style notification with an image", "tags": [], "methods": [], "properties": [ { "name": "style", "tags": [], "docs": "Notification style template used", "complexTypes": [ "NotificationStyle" ], "type": "NotificationStyle.BIG_PICTURE" }, { "name": "bigPicture", "tags": [], "docs": "Base64-encoded picture shown in expanded view", "complexTypes": [], "type": "string | undefined" }, { "name": "pictureContentDescription", "tags": [], "docs": "Content description for the picture", "complexTypes": [], "type": "string | undefined" } ] }, { "name": "InboxNotification", "slug": "inboxnotification", "docs": "Inbox style notification with multiple lines", "tags": [], "methods": [], "properties": [ { "name": "style", "tags": [], "docs": "Notification style template used", "complexTypes": [ "NotificationStyle" ], "type": "NotificationStyle.INBOX" }, { "name": "inboxLines", "tags": [], "docs": "Array of text lines in the inbox", "complexTypes": [], "type": "string[]" } ] }, { "name": "MessagingNotification", "slug": "messagingnotification", "docs": "Messaging style notification for chat/messaging apps", "tags": [], "methods": [], "properties": [ { "name": "style", "tags": [], "docs": "Notification style template used", "complexTypes": [ "NotificationStyle" ], "type": "NotificationStyle.MESSAGING" }, { "name": "category", "tags": [], "docs": "Notification category (call, message, email, etc.)", "complexTypes": [ "NotificationCategory" ], "type": "NotificationCategory.MESSAGE" }, { "name": "conversationTitle", "tags": [], "docs": "Conversation title for group chats", "complexTypes": [], "type": "string | undefined" }, { "name": "isGroupConversation", "tags": [], "docs": "Whether this is a group conversation", "complexTypes": [], "type": "boolean" }, { "name": "messages", "tags": [], "docs": "Array of messages in the conversation", "complexTypes": [ "NotificationMessage" ], "type": "NotificationMessage[]" } ] }, { "name": "NotificationMessage", "slug": "notificationmessage", "docs": "Message in a messaging-style notification", "tags": [], "methods": [], "properties": [ { "name": "text", "tags": [], "docs": "Message text", "complexTypes": [], "type": "string" }, { "name": "timestamp", "tags": [], "docs": "Timestamp of the message", "complexTypes": [], "type": "number" }, { "name": "sender", "tags": [], "docs": "Sender name", "complexTypes": [], "type": "string | undefined" } ] }, { "name": "ProgressNotification", "slug": "progressnotification", "docs": "Progress style notification for downloads, uploads, etc.", "tags": [], "methods": [], "properties": [ { "name": "style", "tags": [], "docs": "Notification style template used", "complexTypes": [ "NotificationStyle" ], "type": "NotificationStyle.DEFAULT" }, { "name": "category", "tags": [], "docs": "Notification category (call, message, email, etc.)", "complexTypes": [ "NotificationCategory" ], "type": "NotificationCategory.PROGRESS" }, { "name": "progress", "tags": [], "docs": "Progress information", "complexTypes": [ "NotificationProgress" ], "type": "NotificationProgress" } ] }, { "name": "NotificationProgress", "slug": "notificationprogress", "docs": "Progress information for notifications with progress bars", "tags": [], "methods": [], "properties": [ { "name": "current", "tags": [], "docs": "Current progress value", "complexTypes": [], "type": "number" }, { "name": "max", "tags": [], "docs": "Maximum progress value", "complexTypes": [], "type": "number" }, { "name": "indeterminate", "tags": [], "docs": "Whether the progress is indeterminate", "complexTypes": [], "type": "boolean" } ] }, { "name": "CallNotification", "slug": "callnotification", "docs": "Call notification", "tags": [], "methods": [], "properties": [ { "name": "style", "tags": [], "docs": "Notification style template used", "complexTypes": [ "NotificationStyle" ], "type": "NotificationStyle.CALL | NotificationStyle.DEFAULT" }, { "name": "category", "tags": [], "docs": "Notification category (call, message, email, etc.)", "complexTypes": [ "NotificationCategory" ], "type": "NotificationCategory.CALL | NotificationCategory.MISSED_CALL" }, { "name": "callerName", "tags": [], "docs": "Caller name", "complexTypes": [], "type": "string | undefined" } ] }, { "name": "MediaNotification", "slug": "medianotification", "docs": "Media playback notification", "tags": [], "methods": [], "properties": [ { "name": "style", "tags": [], "docs": "Notification style template used", "complexTypes": [ "NotificationStyle" ], "type": "NotificationStyle.MEDIA | NotificationStyle.DECORATED_MEDIA" }, { "name": "category", "tags": [], "docs": "Notification category (call, message, email, etc.)", "complexTypes": [ "NotificationCategory" ], "type": "NotificationCategory.TRANSPORT" } ] }, { "name": "GenericNotification", "slug": "genericnotification", "docs": "Generic notification that doesn't fit specific patterns", "tags": [], "methods": [], "properties": [ { "name": "style", "tags": [], "docs": "Notification style template used", "complexTypes": [ "NotificationStyle" ], "type": "NotificationStyle.DECORATED_CUSTOM | NotificationStyle.DEFAULT" } ] }, { "name": "GetNotificationsResult", "slug": "getnotificationsresult", "docs": "Result returned by getNotifications.", "tags": [], "methods": [], "properties": [ { "name": "notifications", "tags": [], "docs": "Array of notifications from the database.", "complexTypes": [ "NotificationItem" ], "type": "NotificationItem[]" } ] }, { "name": "GetNotificationsOptions", "slug": "getnotificationsoptions", "docs": "Options for getNotifications.", "tags": [], "methods": [], "properties": [ { "name": "cursor", "tags": [], "docs": "Return notifications whose timestamp is strictly less than this value (in ms).\nUse the `timestamp` from the last item of the previous page when paginating.", "complexTypes": [], "type": "number | undefined" }, { "name": "limit", "tags": [ { "text": "10", "name": "default" } ], "docs": "Maximum number of notifications to retrieve.", "complexTypes": [], "type": "number | undefined" }, { "name": "filter", "tags": [], "docs": "Optional filter criteria applied on the stored notifications.", "complexTypes": [ "NotificationFilter" ], "type": "NotificationFilter" } ] }, { "name": "NotificationFilter", "slug": "notificationfilter", "docs": "Advanced filters for querying stored notifications.\nEach filter is optional and multiple filters are combined with AND logic.", "tags": [], "methods": [], "properties": [ { "name": "textContains", "tags": [], "docs": "Match notifications whose text contains the provided value (case-sensitive).", "complexTypes": [], "type": "string | undefined" }, { "name": "titleContains", "tags": [], "docs": "Match notifications whose title contains the provided value (case-sensitive).", "complexTypes": [], "type": "string | undefined" }, { "name": "textContainsInsensitive", "tags": [], "docs": "Match notifications whose text contains the provided value (case-insensitive).", "complexTypes": [], "type": "string | undefined" }, { "name": "titleContainsInsensitive", "tags": [], "docs": "Match notifications whose title contains the provided value (case-insensitive).", "complexTypes": [], "type": "string | undefined" }, { "name": "appNames", "tags": [], "docs": "Only return notifications whose `appName` exactly matches one of the supplied names.", "complexTypes": [], "type": "string[] | undefined" }, { "name": "packageName", "tags": [], "docs": "Filter by package name of the posting application.", "complexTypes": [], "type": "string | undefined" }, { "name": "category", "tags": [], "docs": "Filter by notification category.", "complexTypes": [ "NotificationCategory" ], "type": "string | undefined" }, { "name": "style", "tags": [], "docs": "Filter by notification style template.", "complexTypes": [ "NotificationStyle" ], "type": "string | undefined" }, { "name": "isOngoing", "tags": [], "docs": "Filter for ongoing (non-dismissible) notifications only.", "complexTypes": [], "type": "boolean | undefined" }, { "name": "isGroupSummary", "tags": [], "docs": "Filter for group summary notifications only.", "complexTypes": [], "type": "boolean | undefined" }, { "name": "channelId", "tags": [], "docs": "Filter by notification channel ID (Android 8+).", "complexTypes": [], "type": "string | undefined" }, { "name": "afterTimestamp", "tags": [], "docs": "Only return notifications posted after this timestamp (in milliseconds).\nCreates a lower bound for the time range.", "complexTypes": [], "type": "number | undefined" }, { "name": "beforeTimestamp", "tags": [], "docs": "Only return notifications posted before this timestamp (in milliseconds).\nCreates an upper bound for the time range.", "complexTypes": [], "type": "number | undefined" } ] }, { "name": "ImportNotificationsOptions", "slug": "importnotificationsoptions", "docs": "Options for importNotifications.", "tags": [], "methods": [], "properties": [ { "name": "notifications", "tags": [], "docs": "Array of notification items to import into the database.\nEach notification should conform to the NotificationItem type structure.", "complexTypes": [ "NotificationItem" ], "type": "NotificationItem[]" } ] }, { "name": "GetInstalledAppsResult", "slug": "getinstalledappsresult", "docs": "Result returned by getInstalledApps.", "tags": [], "methods": [], "properties": [ { "name": "apps", "tags": [], "docs": "Array of installed applications with their metadata.", "complexTypes": [ "InstalledApp" ], "type": "InstalledApp[]" } ] }, { "name": "InstalledApp", "slug": "installedapp", "docs": "Information about an installed application.", "tags": [], "methods": [], "properties": [ { "name": "packageName", "tags": [], "docs": "The package name of the app.", "complexTypes": [], "type": "string" }, { "name": "appName", "tags": [], "docs": "The human-readable name of the app.", "complexTypes": [], "type": "string" }, { "name": "appIcon", "tags": [], "docs": "Base64-encoded PNG of the app's launcher icon.", "complexTypes": [], "type": "string | undefined" }, { "name": "isSystemApp", "tags": [], "docs": "Whether the app is a system app.", "complexTypes": [], "type": "boolean" } ] }, { "name": "PluginListenerHandle", "slug": "pluginlistenerhandle", "docs": "", "tags": [], "methods": [], "properties": [ { "name": "remove", "tags": [], "docs": "", "complexTypes": [], "type": "() => Promise<void>" } ] } ], "enums": [ { "name": "NotificationStyle", "slug": "notificationstyle", "members": [ { "name": "BIG_TEXT", "value": "'BigTextStyle'", "tags": [], "docs": "" }, { "name": "BIG_PICTURE", "value": "'BigPictureStyle'", "tags": [], "docs": "" }, { "name": "INBOX", "value": "'InboxStyle'", "tags": [], "docs": "" }, { "name": "MESSAGING", "value": "'MessagingStyle'", "tags": [], "docs": "" }, { "name": "MEDIA", "value": "'MediaStyle'", "tags": [], "docs": "" }, { "name": "CALL", "value": "'CallStyle'", "tags": [], "docs": "" }, { "name": "DECORATED_CUSTOM", "value": "'DecoratedCustomViewStyle'", "tags": [], "docs": "" }, { "name": "DECORATED_MEDIA", "value": "'DecoratedMediaCustomViewStyle'", "tags": [], "docs": "" }, { "name": "DEFAULT", "value": "'default'", "tags": [], "docs": "" } ] }, { "name": "NotificationCategory", "slug": "notificationcategory", "members": [ { "name": "ALARM", "value": "'alarm'", "tags": [], "docs": "" }, { "name": "CALL", "value": "'call'", "tags": [], "docs": "" }, { "name": "EMAIL", "value": "'email'", "tags": [], "docs": "" }, { "name": "ERROR", "value": "'err'", "tags": [], "docs": "" }, { "name": "EVENT", "value": "'event'", "tags": [], "docs": "" }, { "name": "LOCATION_SHARING", "value": "'location_sharing'", "tags": [], "docs": "" }, { "name": "MESSAGE", "value": "'msg'", "tags": [], "docs": "" }, { "name": "MISSED_CALL", "value": "'missed_call'", "tags": [], "docs": "" }, { "name": "NAVIGATION", "value": "'navigation'", "tags": [], "docs": "" }, { "name": "PROGRESS", "value": "'progress'", "tags": [], "docs": "" }, { "name": "PROMO", "value": "'promo'", "tags": [], "docs": "" }, { "name": "RECOMMENDATION", "value": "'recommendation'", "tags": [], "docs": "" }, { "name": "REMINDER", "value": "'reminder'", "tags": [], "docs": "" }, { "name": "SERVICE", "value": "'service'", "tags": [], "docs": "" }, { "name": "SOCIAL", "value": "'social'", "tags": [], "docs": "" }, { "name": "STATUS", "value": "'status'", "tags": [], "docs": "" }, { "name": "STOPWATCH", "value": "'stopwatch'", "tags": [], "docs": "" }, { "name": "SYSTEM", "value": "'sys'", "tags": [], "docs": "" }, { "name": "TRANSPORT", "value": "'transport'", "tags": [], "docs": "" }, { "name": "VOICEMAIL", "value": "'voicemail'", "tags": [], "docs": "" }, { "name": "WORKOUT", "value": "'workout'", "tags": [], "docs": "" }, { "name": "UNKNOWN", "value": "'unknown'", "tags": [], "docs": "" } ] } ], "typeAliases": [ { "name": "NotificationItem", "slug": "notificationitem", "docs": "Union type of all specific notification types.\nUse discriminated union on 'style' and 'category' for type narrowing.\n\nType narrowing examples:\n- For BigTextNotification: check `notification.style === NotificationStyle.BIG_TEXT`\n- For BigPictureNotification: check `notification.style === NotificationStyle.BIG_PICTURE`\n- For InboxNotification: check `notification.style === NotificationStyle.INBOX`\n- For MessagingNotification: check `notification.style === NotificationStyle.MESSAGING`\n- For ProgressNotification: check `notification.category === NotificationCategory.PROGRESS`\n- For CallNotification: check category is CALL or MISSED_CALL\n- For MediaNotification: check style is MEDIA or DECORATED_MEDIA", "types": [ { "text": "BigTextNotification", "complexTypes": [ "BigTextNotification" ] }, { "text": "BigPictureNotification", "complexTypes": [ "BigPictureNotification" ] }, { "text": "InboxNotification", "complexTypes": [ "InboxNotification" ] }, { "text": "MessagingNotification", "complexTypes": [ "MessagingNotification" ] }, { "text": "ProgressNotification", "complexTypes": [ "ProgressNotification" ] }, { "text": "CallNotification", "complexTypes": [ "CallNotification" ] }, { "text": "MediaNotification", "complexTypes": [ "MediaNotification" ] }, { "text": "GenericNotification", "complexTypes": [ "GenericNotification" ] } ] } ], "pluginConfigs": [] }