MaikuB / flutter_local_notifications

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

Contextual Actions must contain a valid icon? #2268

Closed tj1334311578 closed 6 months ago

tj1334311578 commented 8 months ago

PlatformException(error, Contextual Actions must contain a valid icon, null, java.lang.NullPointerException: Contextual Actions must contain a valid icon D/StaticsAgent(27908): at android.app.Notification$Action$Builder.checkContextualActionNullFields(Notification.java:2092) D/StaticsAgent(27908): at android.app.Notification$Action$Builder.build(Notification.java:2108) D/StaticsAgent(27908): at androidx.core.app.NotificationCompatBuilder$Api20Impl.build(NotificationCompatBuilder.java:645) D/StaticsAgent(27908): at androidx.core.app.NotificationCompatBuilder.addAction(NotificationCompatBuilder.java:408) D/StaticsAgent(27908): at androidx.core.app.NotificationCompatBuilder.(NotificationCompatBuilder.java:112) D/StaticsAgent(27908): at androidx.core.app.NotificationCompat$Builder.build(NotificationCompat.java:2550) D/StaticsAgent(27908): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:419) D/StaticsAgent(27908): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1248) D/StaticsAgent(27908): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1588) D/StaticsAgent(27908): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1413) D/StaticsAgent(27908): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) D/StaticsAgent(27908): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) D/StaticsAgent(27908): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) D/StaticsAgent(27908): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) D/StaticsAgent(27908): at android.os.Handler.handleCallback(Handler.java:942) D/StaticsAgent(27908): at android.os.Handler.dispatchMessage(Handler.java:99) D/StaticsAgent(27908): at android.os.Looper.loopOnce(Looper.java:201) D/StaticsAgent(27908): at android.os.Looper.loop(Looper.java:288) D/StaticsAgent(27908): at android.app.ActivityThread.main(ActivityThread.java:7884) D/StaticsAgent(27908): at java.lang.reflect.Method.invoke(Native Method) D/StaticsAgent(27908): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) D/StaticsAgent(27908): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) D/StaticsAgent(27908): ) D/StaticsAgent(27908): stack:#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7) D/StaticsAgent(27908): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18) D/StaticsAgent(27908): D/StaticsAgent(27908): #2 FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:240:7) D/StaticsAgent(27908): D/StaticsAgent(27908): #3 NotificationUtil._showNotificationWithNoSound (package:project_speed/app/utils/notification_util.dart:235:5) D/StaticsAgent(27908): D/StaticsAgent(27908): #4 NotificationUtil.startNotification (package:project_speed/app/utils/notification_util.dart:198:5) D/StaticsAgent(27908):

tj1334311578 commented 8 months ago

I initialized it and printed out the corresponding resource id. The call showed a crash.

tj1334311578 commented 8 months ago

参见打印日志:E/initialize: default id:( 4130): 2131165263

tj1334311578 commented 8 months ago

log:E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): Failed to handle method call E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): java.lang.NullPointerException: Contextual Actions must contain a valid icon E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at android.app.Notification$Action$Builder.checkContextualActionNullFields(Notification.java:2092) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at android.app.Notification$Action$Builder.build(Notification.java:2108) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at androidx.core.app.NotificationCompatBuilder$Api20Impl.build(NotificationCompatBuilder.java:645) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at androidx.core.app.NotificationCompatBuilder.addAction(NotificationCompatBuilder.java:408) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at androidx.core.app.NotificationCompatBuilder.(NotificationCompatBuilder.java:112) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at androidx.core.app.NotificationCompat$Builder.build(NotificationCompat.java:2550) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:419) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1249) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1589) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1414) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at android.os.Handler.handleCallback(Handler.java:942) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at android.os.Looper.loopOnce(Looper.java:201) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at android.os.Looper.loop(Looper.java:288) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at android.app.ActivityThread.main(ActivityThread.java:7884) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) E/MethodChannel#dexterous.com/flutter/local_notifications( 4130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) I/flutter ( 4130): TAG v ——animation:false false false I/flutter ( 4130): TAG v object>>> 1.2825396825396826 1.1857142857142857 I/flutter ( 4130): TAG v =====crash:======= I/flutter ( 4130): PlatformException(error, Contextual Actions must contain a valid icon, null, java.lang.NullPointerException: Contextual Actions must contain a valid icon I/flutter ( 4130): at android.app.Notification$Action$Builder.checkContextualActionNullFields(Notification.java:2092) I/flutter ( 4130): at android.app.Notification$Action$Builder.build(Notification.java:2108) I/flutter ( 4130): at androidx.core.app.NotificationCompatBuilder$Api20Impl.build(NotificationCompatBuilder.java:645) I/flutter ( 4130): at androidx.core.app.NotificationCompatBuilder.addAction(Notific I/flutter ( 4130): TAG v ationCompatBuilder.java:408) I/flutter ( 4130): at androidx.core.app.NotificationCompatBuilder.(NotificationCompatBuilder.java:112) I/flutter ( 4130): at androidx.core.app.NotificationCompat$Builder.build(NotificationCompat.java:2550) I/flutter ( 4130): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:419) I/flutter ( 4130): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1249) I/flutter ( 4130): at com.dexterous.flutterlocalnoti I/flutter ( 4130): TAG v fications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1589) I/flutter ( 4130): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1414) I/flutter ( 4130): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) I/flutter ( 4130): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) I/flutter ( 4130): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embe I/flutter ( 4130): TAG v dding-engine-dart-DartMessenger(DartMessenger.java:319) I/flutter ( 4130): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) I/flutter ( 4130): at android.os.Handler.handleCallback(Handler.java:942) I/flutter ( 4130): at android.os.Handler.dispatchMessage(Handler.java:99) I/flutter ( 4130): at android.os.Looper.loopOnce(Looper.java:201) I/flutter ( 4130): at android.os.Looper.loop(Looper.java:288) I/flutter ( 4130): at android.app.ActivityThread.main(ActivityThread.java:7884) I/flutter ( 4130): at java.lang.reflect.Method.invoke(Native Method) I/flutter ( 4130): at com.android.internal.os.RuntimeInit I/flutter ( 4130): TAG v $MethodAndArgsCaller.run(RuntimeInit.java:548) I/flutter ( 4130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) I/flutter ( 4130): ) I/flutter ( 4130): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7) I/flutter ( 4130): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18) I/flutter ( 4130): I/flutter ( 4130): #2 FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:240:7) I/flutter ( 4130): I/flutter ( 4130): #3 Notific I/flutter ( 4130): TAG v ationUtil._showNotificationWithNoSound (package:project_speed/app/utils/notification_util.dart:235:5) I/flutter ( 4130): I/flutter ( 4130): #4 NotificationUtil.startNotification (package:project_speed/app/utils/notification_util.dart:198:5) I/flutter ( 4130):

MaikuB commented 6 months ago

I'm not sure what issue you're trying to describe here. The exception tells you the problem that contextual actions (emphasis on context actions) need an icon. That it's being thrown means you haven't provided one. My assumption is you think the default icon used for initialisation is to related to this and it's not as that is for the notification action

MaikuB commented 6 months ago

Closing as there's been no more response on this and as explained in previous message, the exception explains the cause of the issue