Complete the code to initialize Firebase Cloud Messaging in an Android app.
FirebaseMessaging.getInstance().[1]()The getToken() method retrieves the current registration token for the device, which is needed to receive push notifications.
Complete the code to subscribe the device to a topic named "news" for receiving group notifications.
FirebaseMessaging.getInstance().[1]("news")
The subscribeToTopic() method subscribes the device to a topic so it can receive messages sent to that topic.
Fix the error in the code to handle incoming messages by overriding the correct method in FirebaseMessagingService.
override fun [1](remoteMessage: RemoteMessage) {
// Handle message here
}The onMessageReceived method is called when a message is received. Overriding it lets you handle incoming push notifications.
Fill both blanks to create a notification channel for Android 8.0+ devices.
val channel = NotificationChannel("channel_id", "[1]", [2]) notificationManager.createNotificationChannel(channel)
The first blank is the user-visible channel name. The second blank is the importance level constant IMPORTANCE_HIGH to show notifications prominently.
Fill all three blanks to build and show a notification with a title and text.
val notification = NotificationCompat.Builder(this, "channel_id") .setContentTitle("[1]") .setContentText("[2]") .setSmallIcon([3]) .build() notificationManager.notify(1, notification)
The title is "New Message", the text is "You have a new notification", and the small icon uses the notification icon resource R.drawable.ic_notification.