패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.4.0

flutter_notification_listener

Android용 모든 들어오는 알림을 듣기 위한 Flutter 플러그인입니다.

Android
30일 다운로드
1천
좋아요
67
Pub 점수
140

패키지 설치

flutter pub add flutter_notification_listener

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

안드로이드 앱이 실시간으로 들어오는 알림을 수신하고 접근할 수 있도록 해주는 플러터 플러그인입니다. 개발자가 다른 앱의 알림을 모니터링하고 내용을 추출하여 적절히 반응할 수 있도록 Android의 NotificationListenerService에 대한 브리지 기능을 제공합니다. 생산성 도구, 자동화 앱 또는 접근성 기능과 같이 시스템 전체 알림 이벤트를 분석하거나 반응해야 하는 앱에 이상적입니다. 이 플러그인은 알림 접근 권한을 활성화하기 위해 사용자 허가가 필요하며, 안드로이드에서만 작동합니다.

사용 사례

  • 실시간 알림 모니터링
  • 수신 알림에 대한 응답 자동화
  • 접근성 도구 구축
  • 앱별 알림 추적
  • 알림 기반 워크플로우 만들기

주요 기능

  • 모든 들어오는 Android 알림에 대한 액세스
  • 실시간 이벤트 스트리밍
  • 안드로이드 전용 지원
  • 시스템 수준 알림 접근 권한 필요
  • Flutter와의 간단한 통합

적합한 대상

  • 알림 인식 앱을 개발하는 개발자
  • 앱 간 알림 추적을 필요로 하는 앱
  • 접근성 및 자동화 솔루션
  • Android 중심의 Flutter 애플리케이션

고려 사항

  • 사용자가 수동으로 권한 설정을 해야 합니다
  • Android 플랫폼에 한정
  • 배터리 수명에 영향을 줄 수 있습니다
  • 민감한 데이터를 주의 깊게 처리해야 합니다
  • iOS 또는 기타 플랫폼에서 사용할 수 없습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Flutter Notification Listener

A powerful Flutter plugin for listening to all incoming notifications on Android

Pub Version Pub Points GitHub Stars License

Features · Installation · Quick Start · API Reference · Contributing


✨ Features

🔔 Real-time Listening

Capture all system notifications as they arrive, from any app installed on the device.

🎯 Simple API

Clean and intuitive API design. Access notification fields with ease.

⚡ Background Execution

Run Dart code in the background. Auto-start service after device reboot.

🎮 Interactive

Tap notifications, trigger actions, and even auto-reply to messages directly from Flutter.

Compatibility
Android Version API Level Status
Android 14 API 34 ✅ Fully Supported
Android 13 API 33 ✅ Fully Supported
Android 12 API 31-32 ✅ Fully Supported
Android 11 and below API ≤ 30 ✅ Fully Supported

📦 Installation

Add the dependency to your pubspec.yaml:

dependencies:
  flutter_notification_listener: ^1.4.0

Then run:

flutter pub get

🚀 Quick Start

Step 1: Configure Android Manifest

Add the notification listener service inside the <application> tag:

<service 
    android:name="im.zoe.labs.flutter_notification_listener.NotificationsHandlerService"
    android:label="Flutter Notifications Handler"
    android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
    android:exported="true"
    android:foregroundServiceType="specialUse">
    <property 
        android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
        android:value="notification_listener"/>
    <intent-filter>
        <action android:name="android.service.notification.NotificationListenerService" />
    </intent-filter>
</service>

Add required permissions:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>

Note: For Android 13+, request the POST_NOTIFICATIONS permission at runtime before starting the foreground service.

Step 2: Initialize the Plugin
import 'package:flutter_notification_listener/flutter_notification_listener.dart';

void onData(NotificationEvent event) {
  print('${event.packageName}: ${event.title} - ${event.text}');
}

Future<void> initPlatformState() async {
  NotificationsListener.initialize();
  NotificationsListener.receivePort?.listen((evt) => onData(evt));
}
Step 3: Start the Service
Future<void> startListening() async {
  final hasPermission = await NotificationsListener.hasPermission ?? false;
  
  if (!hasPermission) {
    NotificationsListener.openPermissionSettings();
    return;
  }

  final isRunning = await NotificationsListener.isRunning ?? false;
  
  if (!isRunning) {
    await NotificationsListener.startService(
      foreground: true,
      title: "Listening for notifications",
    );
  }
}

📖 See the example app for a complete implementation.


📖 Usage Guide

Auto-start After Reboot

Register a broadcast receiver to automatically restart the service after device reboot:

<receiver 
    android:name="im.zoe.labs.flutter_notification_listener.RebootBroadcastReceiver"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

Add the boot permission:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Background Processing

For reliable background execution, use a static callback function:

@pragma('vm:entry-point')
static void _callback(NotificationEvent evt) {
  // Persist data immediately
  db.save(evt);
  
  // Forward to UI thread if needed
  final send = IsolateNameServer.lookupPortByName("_listener_");
  send?.send(evt);
}

Future<void> initPlatformState() async {
  NotificationsListener.initialize(callbackHandle: _callback);
}

Important: The @pragma('vm:entry-point') annotation is required for Flutter 3.x to prevent the function from being stripped in release builds.

Interactive Notifications

Tap a notification:

void onData(NotificationEvent event) {
  if (event.canTap) {
    event.tap();
  }
}

Auto-reply to messages:

void onData(NotificationEvent event) {
  for (final action in event.actions ?? []) {
    if (action.semantic == 1) { // SEMANTIC_ACTION_REPLY
      final inputs = <String, dynamic>{};
      for (final input in action.inputs ?? []) {
        inputs[input.resultKey ?? ''] = "Auto-reply from Flutter";
      }
      action.postInputs(inputs);
    }
  }
}
Customize Service Notification
await NotificationsListener.startService(
  foreground: true,
  title: "My App",
  description: "Listening for notifications...",
);

📚 API Reference

NotificationEvent
Property Type Description
uniqueId String Unique identifier generated from key
packageName String Source application package name
title String? Notification title
text String? Notification body text
timestamp int Post time (milliseconds since epoch)
channelId String? Notification channel ID (API 26+)
largeIcon Uint8List? Large icon as bytes
canTap bool Whether notification has a tap action
actions List<Action>? Available notification actions
raw Map<String, dynamic> Raw notification data

Methods:

Method Returns Description
tap() Future<bool> Trigger the notification's tap action
getFull() Future<dynamic> Get complete notification data
Action
Property Type Description
id int Action index
title String? Action button text
semantic int Semantic type (see below)
inputs List<ActionInput>? Input fields for reply actions

Semantic Types:

Constant Value Description
SEMANTIC_ACTION_NONE 0 No semantic
SEMANTIC_ACTION_REPLY 1 Quick reply
SEMANTIC_ACTION_MARK_AS_READ 2 Mark as read
SEMANTIC_ACTION_MARK_AS_UNREAD 3 Mark as unread
SEMANTIC_ACTION_DELETE 4 Delete
SEMANTIC_ACTION_ARCHIVE 5 Archive
SEMANTIC_ACTION_MUTE 6 Mute
SEMANTIC_ACTION_UNMUTE 7 Unmute
NotificationsListener
Method Description
initialize({callbackHandle}) Initialize the plugin
hasPermission Check notification access permission
isRunning Check if service is running
openPermissionSettings() Open system permission settings
startService({...}) Start the listener service
stopService() Stop the listener service
promoteToForeground({...}) Promote service to foreground
demoteToBackground() Demote service to background

⚠️ Known Issues

  • Service may fail to start after reboot if not running in foreground mode.

💖 Support

If you find this plugin useful, please consider:

  • ⭐ Starring the repository
  • 🐛 Reporting bugs
  • 💡 Suggesting new features
  • 🤝 Contributing code

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Made with ❤️ by Zoe

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.