当前位置: 首页 > 知识库问答 >
问题:

无法处理本地通知的方法调用

禹昊穹
2023-03-14
FlatButton(
            onPressed: () {
              FlutterLocalNotificationsPlugin localNotifPlugin =
                  new FlutterLocalNotificationsPlugin();
              var androidChannelSpecifics = AndroidNotificationDetails(
                  'default',
                  'Test App Notifications',
                  'Channel for default notifications from test app');
              var iOSChannelSpecifics = IOSNotificationDetails();
              var platformChannelSpecifics = NotificationDetails(
                  androidChannelSpecifics, iOSChannelSpecifics);
              localNotifPlugin.show(
                  0,
                  "Test Notificaiton",
                  "This is your test notification! :)",
                  platformChannelSpecifics);
            },
            child: Text("Show Notification"),
          )
    D/EGL_emulation(24401): eglMakeCurrent: 0xa80053c0: ver 2 0 (tinfo 0xa8003360)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(24401): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:156)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:131)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:598)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:690)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:619)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at android.os.MessageQueue.next(MessageQueue.java:323)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at android.os.Looper.loop(Looper.java:136)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at android.app.ActivityThread.main(ActivityThread.java:6077)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
E/flutter (24401): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null)
E/flutter (24401): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (24401): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
E/flutter (24401): <asynchronous suspension>
E/flutter (24401): #2      FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications.dart:120:20)
E/flutter (24401): <asynchronous suspension>
E/flutter (24401): #3      HomePage.build.<anonymous closure> (package:provider_test/main.dart:53:36)
E/flutter (24401): #4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
E/flutter (24401): #5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:729:32)
E/flutter (24401): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (24401): #7      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter (24401): #8      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
E/flutter (24401): #9      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
E/flutter (24401): #10     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
E/flutter (24401): #11     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
E/flutter (24401): #12     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (24401): #13     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (24401): #14     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (24401): #15     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (24401): #16     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (24401): #17     _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (24401): #18     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (24401): #19     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (24401): #20     _invoke1 (dart:ui/hooks.dart:263:10)
E/flutter (24401): #21     _dispatchPointerDataPacket (dart:ui/hooks.dart:172:5)

共有1个答案

高皓
2023-03-14

看起来您正在初始化插件,没有或带有错误的app_icon;

在initState中,您应该使用正确的图标名称进行初始化:

@override
 void initState() {
   super.initState();
   FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
   var initializationSettingsAndroid = AndroidInitializationSettings('app_icon'); // <- default icon name is @mipmap/ic_launcher
   var initializationSettingsIOS = IOSInitializationSettings(onDidReceiveLocalNotification: onDidReceiveLocalNotification);
   var initializationSettings = InitializationSettings(initializationSettingsAndroid, initializationSettingsIOS);
   flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onSelectNotification); }

https://github.com/maikub/flutter_local_notifications#gett-start<-如何初始化

 类似资料:
  • 我正在开发一个Spring boot应用程序,它使用了很多其他第三方库。所有这些库都构建在spring核心之上。通常出现的常见问题是。假设不同库中的bean-name相同,spring在尝试启动服务器时抛出错误。因为我不能控制第三方罐子。我必须重命名我的应用程序中的bean:下面是我为处理这个场景而编写的代码片段。但这不是一个有效的解决方案,因为将来可能会再次出现一些重复的bean。我如何以通用的

  • 我有以下控制器类 } 对于异常处理,我使用Spring3。2.建议如下: } 我将XML bean定义为 控制器通知处理程序不处理从控制器引发的异常。我在谷歌上搜索了几个小时,但找不到它发生的原因。我照着描述的做了http://www.baeldung.com/2013/01/31/exception-handling-for-rest-with-spring-3-2/在这里 如果有人知道,请告诉

  • 本文向大家介绍java通过jni调用opencv处理图像的方法,包括了java通过jni调用opencv处理图像的方法的使用技巧和注意事项,需要的朋友参考一下 1. 建立java文件 2. 切换到工程src文件夹 javac getImageFeature.java javah getImageFeature 生成 getImageFeature.h 文件 3. VS2013建立dll工程 添加g

  • 我正在使用Spring AOP实现自定义注释处理。我有下面的代码。 //应用程序配置 出于测试目的,我创建了下面的bean 无论何时启动应用程序,它都将调用TestCacheDemo类的test方法,并将定时器设置为在3秒后触发,这样我就可以从timer任务的run方法内部调用带注释的方法getCacheValue。但是当调用带注释的方法时,不会调用注释处理器。因此,我无法进行注释处理。请让我知道

  • 问题内容: 可以编译并运行: 这不会(产生标题中的错误): 有人可以帮我理解为什么吗?(学习围棋) 这些是这些方法: 问题答案: 该方法有一个 指针 接收器,因此要调用此方法,需要一个指向值的指针()。在第一个示例中,您将的返回值存储在类型为的变量中。 Go中的变量是可寻址的,并且在编写时,这是一个快捷方式,编译器将自动获取变量的地址,以具有必需的类型的接收者值以进行调用。因此,编译器会将其“转换

  • 我知道类似的问题已经被问过很多次了。但在阅读了这些帖子之后,我仍然感到非常困惑,尤其是在iOS 10中引入了之后。 官方文档提到了我可以处理远程通知的3种方法: 实现以在应用程序位于前台时处理通知 当应用程序处于后台或未运行时,实现 但文档中也提到:在iOS和tvOS中,系统将通知有效负载传递给app委托的方法 所以 要在应用处于后台/非活动状态时处理远程通知,我应该将我的代码放在3中的应用程序委