MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.45k stars 1.39k forks source link

Exception while trying to read notification channels #2318

Closed ueman closed 5 months ago

ueman commented 5 months ago

Describe the bug

The following code

final _localNotifications = FlutterLocalNotificationsPlugin();
final androidPlugin = _localNotifications.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>();
final allChannels = await androidPlugin?.getNotificationChannels();

results in the following exception

PlatformException(getNotificationChannelsError, Attempt to invoke virtual method 'int android.media.AudioAttributes.getUsage()' on a null object reference, java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.AudioAttributes.getUsage()' on a null object reference
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.getMappedNotificationChannel(FlutterLocalNotificationsPlugin.java:265)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.getNotificationChannels(FlutterLocalNotificationsPlugin.java:32)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:399)
    at me.j$a.a(MethodChannel.java:18)
    at ae.c.l(DartMessenger.java:19)
    at ae.c.m(DartMessenger.java:42)
    at ae.c.h(Unknown Source:0)
    at ae.b.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:257)
    at android.os.Looper.loop(Looper.java:368)
    at android.app.ActivityThread.main(ActivityThread.java:8826)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
, null)

To Reproduce Unfortunately, we're seeing this only in production without any actionable reproduction steps. The app is in foreground and active, though.

Expected behavior I expect no exception to be thrown.

Sample code to reproduce the problem See above

This is not a duplicate of https://github.com/MaikuB/flutter_local_notifications/issues/2309 but it's pretty similar.

MaikuB commented 5 months ago

Thanks for raising. Fix has been published in version 17.1.2