Reputation: 197
I've seen two tutorials about sending push messages from server with PHP to android devices through firebase cloud messaging and it works fine. But both tutorials have the FirebaseMessagingService class and I don't understand what's the purpose of it?? They don't explain a bit about it.
This is it:
class FirebaseMessagingService : com.google.firebase.messaging.FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
showNotification(remoteMessage!!.data["message"]!!)
}
private fun showNotification(message: String) {
val i = Intent(this, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)
val builder = NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("FCM Test")
.setContentText(message)
.setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
.setContentIntent(pendingIntent)
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.notify(0, builder.build())
}
}
Can I send push notifications from android with it? I just need to send push messages from PHP so can I delete it? The overview of my project is already messy and hard to follow and I don't want any useless stuff in there. Thanks in advance
Upvotes: 1
Views: 839
Reputation: 445
This class is responsible for handling income message. The function onMessageReceived
will be invoked when there is incoming data
message no matter your app is in foreground or background. More specifically, this method is for you to customize the handling of key:value
pair in data
payload
You can leave it there if you are not going to do any special handling. Please read here for more information.
Upvotes: 1