notification_listener_service
A flutter plugin for interacting with Notification Service in Android.
NotificationListenerService is a service that receives calls from the system when new notifications are posted or removed,
for more info check NotificationListenerService
Installation and usage
Add package to your pubspec:
dependencies:
notification_listener_service: any
Inside AndroidManifest add this to bind notification service with your application
<service android:label="notifications" android:name="notification.listener.service.NotificationListener"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" android:exported="true">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
USAGE
final bool status = await NotificationListenerService.isPermissionGranted();
final bool status = await NotificationListenerService.requestPermission();
NotificationListenerService.notificationsStream.listen((event) {
log("Current notification: $event");
});
The ServiceNotificationEvent provides:
int? id;
bool? canReply;
bool? haveExtraPicture;
bool? hasRemoved;
Uint8List? extrasPicture;
Uint8List? largeIcon;
String? packageName;
String? title;
Uint8List? appIcon;
String? content;
Future<bool> sendReply(String message)
To reply to a notification provides:
try {
await event.sendReply("This is an auto response");
} catch (e) {
log(e.toString());
}
Example of the app on foreground
Find the exemple app Here
Screenshots