android_notification_listener 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

Android Notification Listener #

This plugin ( only availaible on Android due to iOS restrictions ) will allow you to listen to any incoming notifications on an Android device running on Android APi level 21 or more . In another word you can read notifications coming from all the installed applications with deep details

Note: This pluggin is a Fork of the original plugin made by Cachet which has some bugs causing frequent crashes and is missing features and details, so I fixed it and added more features :)

Features #

Here are the details you will get from a notification

  • The time Stamp
  • The package name
  • The package message
  • The package text
  • The package extra

Note: The PackageExtra contains more details about each individual notification. It is originally a bundle file. I converted it into a Json and give it to you as a Json String so if you need to use the PackageExtra you will have to json decode it as follow

var jsonDatax = json.decode(event.packageExtra);
print(jsonDatax);

You can refer the example folder for more detail

Here are the extra data you will get from the PackageExtra

  • android.title
  • android.reduced.images
  • android.template
  • android.text
  • android.foregroundApps
  • android.bigText

Android Setup #

Register a service in the Android Manifest

The plugin uses an Android system service to track notifications. To allow this service to run on your application, the following code should be put inside the Android manifest, between the tags.

<service android:name="com.emilecode.android_notification_listener.AndroidNotificationListenerPlugin"
    android:label="notifications"
    android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
    <intent-filter>
        <action android:name="android.service.notification.NotificationListenerService" />
    </intent-filter>
</service>

Listen to notification events

AndroidNotificationListener _notifications;
StreamSubscription<NotificationEvent> _subscription;
events = notifications.stream.listen(onData);

Where the onData() method handles the incoming NotificationEvents. An example could be:

void onData(NotificationEvent event) => print(event.toString());

Conclusion #

Thank you for using my package, if you have any question feel free to contact me on instagram or directly on my mail emile@emilecode.com

Here are my other packages

  • Ultimate Data Generator: generate realistic datas
  • Sliding Card: Animated card that slides down to reveal its hidden part
  • AdvFab: An Advanced floating action button that expands itself to reveal its hidden widget. It can also be used as an AnimatedbottomNavigationbar or just an AnimatedFloatingActionBar with the same expansion capabilities.

0.0.1 16/05/2020 #

  • Pre-Release

1.0.0 16/05/2020 #

  • Initial Release
  • TODO: Update the documentation

1.0.1 16/05/2020 #

  • Fixes
  • Added The Home Page
  • Fixed The documentation

1.0.2 16/05/2020 #

  • Fixed Demo example code that was not compiling
  • Updated image link to point directly to the image inside the git
  • Fixed The documentation

1.0.3 16/05/2020 #

  • Minor fix

example/lib/main.dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:android_notification_listener/android_notification_listener.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  AndroidNotificationListener _notifications;
  StreamSubscription<NotificationEvent> _subscription;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    startListening();
  }

  void onData(NotificationEvent event) {
    
    print(event);
    print('converting package extra to json');
    var jsonDatax = json.decode(event.packageExtra);
    print(jsonDatax);
  }

  void startListening() {
    _notifications = new AndroidNotificationListener();
    try {
      _subscription = _notifications.notificationStream.listen(onData);
    } on NotificationException catch (exception) {
      print(exception);
    }
  }

  void stopListening() {
    _subscription.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  android_notification_listener: ^1.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:android_notification_listener/android_notification_listener.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:android_notification_listener/android_notification_listener.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:android_notification_listener/android_notification_listener.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:android_notification_listener/android_notification_listener.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:android_notification_listener/android_notification_listener.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • android_notification_listener that is a package requiring null.

Health suggestions

Format lib/android_notification_listener.dart.

Run flutter format to format lib/android_notification_listener.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test