Firebase messaging-handle background message in kotlin

后端 未结 1 1275
小鲜肉
小鲜肉 2021-02-08 09:37

I\'m using firebase_messaging in my flutter application. To handle background messages with firebase messaging in pub they suggested to create new Application.java file and rep

1条回答
  •  难免孤独
    2021-02-08 10:24

    Here is the working background notification kotlin code:

    package com.example.yourapp
    
    import io.flutter.app.FlutterApplication
    import io.flutter.plugin.common.PluginRegistry
    import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
    import io.flutter.plugins.GeneratedPluginRegistrant
    import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
    
    class Application : FlutterApplication(), PluginRegistrantCallback {
    
        override fun onCreate() {
            super.onCreate()
            FlutterFirebaseMessagingService.setPluginRegistrant(this);
        }
    
        override fun registerWith(registry: PluginRegistry?) {
            io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
        }
    }
    

    0 讨论(0)
提交回复
热议问题