flutter_local_notifications
flutter_local_notifications copied to clipboard
Unable to start receiver - com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver: java.lang.NullPointerException
Describe the bug
Crash log found on Crashlytics.
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setupNotificationChannel(FlutterLocalNotificationsPlugin.java:1172)
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:251)
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1237)
at com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver.onReceive(ScheduledNotificationReceiver.java:61)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4376)
at android.app.ActivityThread.-$$Nest$mhandleReceiver()
I am using plugin version 16.2.0
Line FlutterLocalNotificationsPlugin.java:1172 shows:
new NotificationChannel(
notificationChannelDetails.id,
notificationChannelDetails.name,
notificationChannelDetails.importance);
or more explicitly:
notificationChannelDetails.importance
I am using the plugin to upgrade a very old Android native app. Is it possible that the old app was scheduling notifications without setting the channel importance? Could this explain the crash?
Looking at NotificationChannelDetails.java:51
public static NotificationChannelDetails from(Map<String, Object> arguments) {
NotificationChannelDetails notificationChannel = new NotificationChannelDetails();
notificationChannel.id = (String) arguments.get(ID);
notificationChannel.name = (String) arguments.get(NAME);
notificationChannel.description = (String) arguments.get(DESCRIPTION);
notificationChannel.groupId = (String) arguments.get(GROUP_ID);
notificationChannel.importance = (Integer) arguments.get(IMPORTANCE);
If arguments.get(IMPORTANCE)
return null this scenario could be happening.
Would it be worth considering using a default importance value when arguments.get(IMPORTANCE)
is null?
Is it possible that the old app was scheduling notifications without setting the channel importance?
It may look that way but would be very odd and you would need to look at version control for your app to determine. I'm saying that it's odd as importance has been part of providing channel information together from the beginning. The plugin had also set a default value so the only idea that comes to mind is if your app used version before the plugin migrated to null-safety (which was 5.0.0) and had your app explicitly specify the importance as null. Even if that were the case, I would've expected that your app would have had similar issues reported back then.
The other potential reason that has been common for issues similar to this is from not configuring the Proguard rules properly and ensuring that has stayed up to date upon updating to new versions of the plugin. I suspect this is more likely given what I mentioned on how I would've expected this to have cropped up earlier if it was due to a null value. It may be possible you need to consider a fork if that were the case and coalesce a null importance to what your app uses as I'm not sure fixing your app's Proguard rules will retroactively fix the problem for older notifications