搜尋套件、儲存庫與 APP 分類

套件詳情v1.0.0

notification_listener_service

Flutter 插件,用於監聽所有傳入的通知(發佈或刪除),並支援回覆通知

Android
近 30 天下載
3220
喜歡數
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

所屬分類

原始碼儲存庫

使用此套件的專案