java.lang.IllegalArgumentException:服务未注册:ls@1ff721a

问题描述

我正在使用 firebase_messaging 7.0.3flutter_local_notifications 4.0.0 在 android 中发送通知,一切正常,我也使用 sqlite 来保存通知,除非后台模式我可以看到通知来,否则它仍然可以正常工作但看起来像我为保存通知而创建的函数没有调用

代码句柄通知

    _firebaseMessaging.configure(
  onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,onMessage: (Map<String,dynamic> message) async {
    MessageNotification notification = MessageNotification(
        id: null,title: message['notification']['title'],body: message['notification']['body'],status: 'U',createdDate: formatted);
    await dbHelper.save(notification);

    showNotification(
        message['notification']['title'],message['notification']['body']);
    messages = await dbHelper.getMessages();
    if (messages.isEmpty) {
      messages = [];
    }
    update();

    print("onLaunch: $message");
  },onLaunch: (Map<String,dynamic> message) async {
    print("onLaunch: $message");
    showNotification(
        message['notification']['title'],message['notification']['body']);
  },onResume: (Map<String,dynamic> message) async {
    print("onResume: $message");
    showNotification(
        message['notification']['title'],message['notification']['body']);
    messages = await dbHelper.getMessages();
    update();
  },);

}

代码处理后台保存

Database db;
const String ID = 'id';
const String TITLE = 'title';
const String BODY = 'body';
const String STATUS = 'status';
const String CREATEDDATE = 'createdDate';
const String TABLE = 'Message';
const String DB_NAME = 'message2.db';
Future<dynamic> myBackgroundMessageHandler(Map<String,dynamic> message) async {
  print('on background running');
  MessageNotification notification = MessageNotification(
      id: null,title: "Hello",body: "hello",createdDate: "2020-10-2020");

  await db.insert(TABLE,notification.toMap());


  return Future<void>.value();

  // Or do other work.
}

应用程序.java

public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
    super.onCreate();
    FlutterFirebaseMessagingService.setPluginRegistrant(this);
}

@Override
public void registerWith(PluginRegistry registry) {
    FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.Flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
    FlutterlocalnotificationsPlugin.registerWith(registry.registrarFor("com.dexterous.Flutterlocalnotifications.FlutterlocalnotificationsPlugin"));
    PathProviderPlugin.registerWith(registry.registrarFor("io.Flutter.plugins.pathprovider.PathProviderPlugin"));
    SqflitePlugin.registerWith(registry.registrarFor("com.tekartik.sqflite.SqflitePlugin"));
}

}

错误日志

W/ConnectionTracker(25834): Exception thrown while unbinding
W/ConnectionTracker(25834): java.lang.IllegalArgumentException: Service not registered: 
ls@1ff721a
W/ConnectionTracker(25834):     at 
android.app.LoadedApk.forgetServicedispatcher(LoadedApk.java:1757)
W/ConnectionTracker(25834):     at 
android.app.ContextImpl.unbindService(ContextImpl.java:1874)
W/ConnectionTracker(25834):     at 
android.content.Contextwrapper.unbindService(Contextwrapper.java:792)
W/ConnectionTracker(25834):     at 
ci.f(:com.google.android.gms.dynamite_measurementdynamite@205016100@20.50.16 (150700-0):1)
W/ConnectionTracker(25834):     at 
ci.d(:com.google.android.gms.dynamite_measurementdynamite@205016100@20.50.16 (150700-0):2)
W/ConnectionTracker(25834):     at 
lt.E(:com.google.android.gms.dynamite_measurementdynamite@205016100@20.50.16 (150700-0):9)
W/ConnectionTracker(25834):     at 
ld.a(:com.google.android.gms.dynamite_measurementdynamite@205016100@20.50.16 (150700-0):3)
W/ConnectionTracker(25834):     at 
ef.run(:com.google.android.gms.dynamite_measurementdynamite@205016100@20.50.16 (150700-0):3)
W/ConnectionTracker(25834):     at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
W/ConnectionTracker(25834):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/ConnectionTracker(25834):     at 
iy.run(:com.google.android.gms.dynamite_measurementdynamite@205016100@20.50.16 (150700-0):5)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...