搜索插件、代码仓与 APP 分类

插件详情v1.0.0

notification_listener_service

Flutter 插件,用于监听所有传入的通知(发布或删除),并支持回复通知

Android
近 30 天下载
3650
喜欢数
72
Pub 分数
160

安装插件

flutter pub add notification_listener_service

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个适用于 Android 的 Flutter 插件,可让应用程序监听传入的通知,包括通知的发布和移除。它支持直接从应用中回复通知,非常适合用于消息传递或自动化工具。该插件利用 Android 的 NotificationListenerService API 实时监控系统通知。开发者可以访问通知的详细信息,如标题、文本、包名和时间戳。需要用户授权以启用监听服务,确保隐私和安全。专为 Android 设计,可无缝集成到现有的 Flutter 项目中。

适合场景

  • 实时通知监控
  • 自动消息回复
  • 基于通知的工作流
  • 应用与系统通知的集成
  • 隐私感知的通知跟踪

主要特点

  • 监听所有传入和移除的通知
  • 支持直接回复功能
  • 仅限 Android 平台的兼容性
  • 基于权限的安全访问
  • 提供详细的通知元数据

适合对象

  • 开发通知自动化工具的开发者
  • 需要实时通知洞察的应用程序
  • 消息或聊天应用程序
  • 系统级 Android 集成
  • 注重隐私的通知处理程序

使用建议

  • 需要 Android 特定的设置和权限
  • 用户必须手动启用监听服务
  • 仅限Android平台
  • 持续监听可能影响电池寿命
  • 敏感数据访问需要谨慎处理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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 # or the latest version on Pub

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
 /// check if notification permession is enebaled
 final bool status = await NotificationListenerService.isPermissionGranted();

 /// request notification permission
 /// it will open the notifications settings page and return `true` once the permission granted.
 final bool status = await NotificationListenerService.requestPermission();

 /// stream the incoming notification events
  NotificationListenerService.notificationsStream.listen((event) {
    log("Current notification: $event");
  });

The ServiceNotificationEvent provides:

  /// the notification id
  int? id;

  /// check if we can reply the Notification
  bool? canReply;

  /// if the notification has an extras image
  bool? haveExtraPicture;

  /// if the notification has been removed
  bool? hasRemoved;

  /// notification extras image
  /// To display an image simply use the [Image.memory] widget.
  Uint8List? extrasPicture;

  /// notification large icon
  /// To display an image simply use the [Image.memory] widget.
  Uint8List? largeIcon;

  /// notification package name
  String? packageName;

  /// notification title
  String? title;

  /// the notification app icon
  /// To display an image simply use the [Image.memory] widget.
  Uint8List? appIcon;

  /// the content of the notification
  String? content;

  /// send a direct message reply to the incoming notification
  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

所属分类

源码仓库

使用此插件的项目