capacitor-notificationlistener
Observe android notification being posted / removed using this NotificationListenerService wrapper for capacitor.
Installation
npm i capacitor-notificationlistener
npx cap sync
Register this plugin using add(NotificationListenerPlugin.class)
in your MainActivity.java
like in the following example:
// ... code ... // ... code ... this.;// ... code ...
Permissions
Add the following, contained in <application>
, to your AndroidManifest.xml:
Usage
Import the plugin.
;;
Start listening for notifications.
sn.startListening;
Add a listener for new notifications or the removal of notifications.
Make sure you have called sn.startListening()
to be able to receive notifications.
sn.addListener"notificationReceivedEvent",;sn.addListener"notificationRemovedEvent",;
SystemNotification Interface. The anotomy of android notifications is explained here.
Check if the App is listening for notifications.
If it is not, even though sn.startListening()
was called,
your app doesn't have sufficient permissions to observe notifications.
sn.isListening.then;
Open settings so that the user can authorize your app.
sn.requestPermission;
Stop listening for notifications.
sn.stopListening;