Complete the code to create a notification channel with the given ID.
val channel = NotificationChannel("[1]", "Channel Name", NotificationManager.IMPORTANCE_DEFAULT)
The channel ID must be a unique string to identify the notification channel. Here, "channel_id_01" is used as the ID.
Complete the code to get the NotificationManager system service.
val notificationManager = context.getSystemService([1]) as NotificationManager
The constant NOTIFICATION_SERVICE is used to get the notification service from the context.
Fix the error in the code to create a notification channel only on Android Oreo or higher.
if (Build.VERSION.SDK_INT >= [1]) { notificationManager.createNotificationChannel(channel) }
Notification channels were introduced in Android Oreo (API level 26), so the check must be against Build.VERSION_CODES.O.
Fill both blanks to build a notification with a small icon and a title.
val notification = Notification.Builder(context, "channel_id_01") .setSmallIcon([1]) .setContentTitle([2]) .build()
The small icon must be a drawable resource ID, and the content title is a string shown in the notification header.
Fill all three blanks to send the notification with ID 1001.
val [3] = Notification.Builder(context, "channel_id_01") .setSmallIcon(R.drawable.ic_notification) .setContentTitle("Hello") .build() notificationManager.[1](1001, [2])
The notify() method sends the notification with an ID. The notification object must be passed as the second argument. The variable holding the notification is named 'notification'.