flutter-plugins
flutter-plugins copied to clipboard
Notifications 2.0.1 critical bug
Device and OS
- Device: OnePlus 9
- OS: Android 12
Describe the bug
The plugin crashes the app with a NullPointerException after receiving a notification that doesn't have a message field.
To Reproduce
Steps to reproduce the behavior.
- Start the NotificationListener service
- Receive a notification without a message field
Expected behavior
The notification is received and has a message equal to an empty string.
Actual behavior
The application crashes with an unhandled NullPointerException in the Java code of the plugin.
I/NotificationsPlugin(12695): Started the notification tracking service.
D/ColorModeChangeItem(12695): preExecute mColorMode=0,token=android.os.BinderProxy@d159d6d
D/AndroidRuntime(12695): Shutting down VM
E/AndroidRuntime(12695): FATAL EXCEPTION: main
E/AndroidRuntime(12695): Process: com.example.balance_front, PID: 12695
E/AndroidRuntime(12695): java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
E/AndroidRuntime(12695): at dk.cachet.notifications.NotificationListener.onNotificationPosted(NotificationListener.java:41)
E/AndroidRuntime(12695): at android.service.notification.NotificationListenerService.onNotificationPosted(NotificationListenerService.java:444)
E/AndroidRuntime(12695): at android.service.notification.NotificationListenerService$MyHandler.handleMessage(NotificationListenerService.java:2305)
E/AndroidRuntime(12695): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(12695): at android.os.Looper.loopOnce(Looper.java:233)
E/AndroidRuntime(12695): at android.os.Looper.loop(Looper.java:344)
E/AndroidRuntime(12695): at android.app.ActivityThread.main(ActivityThread.java:8184)
E/AndroidRuntime(12695): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(12695): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
E/AndroidRuntime(12695): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
I/Process (12695): Sending signal. PID: 12695 SIG: 9
Lost connection to device.
Screenshots
The screenshot of the notification without the message field.

Flutter doctor
D:\Dev\Dart\Flutter\balance_front>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19044.1645], locale ru-UA)
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.9)
[√] Android Studio (version 2021.1)
[√] IntelliJ IDEA Ultimate Edition (version 2022.1)
[√] VS Code (version 1.66.2)
[√] Connected device (4 available)
[√] HTTP Host Availability
• No issues found!
Additional information
Solution suggestion
The exception may be avoided by adding null checks for CharSequence objects in onNotificationPosted method of the dk.cachet.notifications.NotificationListener.
since this package is outdated I have created a similar package you can take a look here notification_listener_service