Home > Back-end >  remoteMessage firebase expecting function invocation
remoteMessage firebase expecting function invocation

Time:02-18

I'm learning firebase cloud messaging. I've implemented it in app run notification, but it seems that doesn't work. The problem is that, when I use the firebase keyword called remoteMessage, it says that it needs to be an invocation. Here's the code:

package com.example.fbtutorial

import android.os.Looper
import android.widget.Toast
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.google.firebase.messaging.ktx.remoteMessage

class MyFirebaseMessagingService : FirebaseMessagingService() {
    override fun onMessageReceived(p0: RemoteMessage) {

        Looper.prepare()

        Toast.makeText(baseContext, remoteMessage.notification?.title, Toast.LENGTH_LONG).show() // here at remoteMessage I have and error saying "Function invocation 'remoteMessage(...)' expected"

        Looper.loop()
    }
}

if you know why i get this error please tell me, thanks in advance.

CodePudding user response:

Your RemoteMessage parameter to onMessageReceived is called p0, so to get its title you'd do:

p0.notification?.title

I recommend carefully reading and following the code in the Firebase documentation on overriding onMessageReceived, as using the parameter names that are used there makes it more likely that your other code will also compile without syntax errorss

  • Related