0
0
Android Kotlinmobile~10 mins

Notification channels in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a notification channel with the given ID.

Android Kotlin
val channel = NotificationChannel("[1]", "Channel Name", NotificationManager.IMPORTANCE_DEFAULT)
Drag options to blanks, or click blank then click option'
Anotification_id
Bchannel_id_01
Cdefault_channel
Dmy_channel
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name instead of a string literal.
Leaving the channel ID blank.
2fill in blank
medium

Complete the code to get the NotificationManager system service.

Android Kotlin
val notificationManager = context.getSystemService([1]) as NotificationManager
Drag options to blanks, or click blank then click option'
Anotification_service
BNotificationManager
CNOTIFICATION_MANAGER_SERVICE
DNOTIFICATION_SERVICE
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of the service constant.
Using incorrect capitalization.
3fill in blank
hard

Fix the error in the code to create a notification channel only on Android Oreo or higher.

Android Kotlin
if (Build.VERSION.SDK_INT >= [1]) {
    notificationManager.createNotificationChannel(channel)
}
Drag options to blanks, or click blank then click option'
ABuild.VERSION_CODES.O
BBuild.VERSION_CODES.M
CBuild.VERSION_CODES.P
DBuild.VERSION_CODES.N
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong API level constant.
Not checking the API level before creating the channel.
4fill in blank
hard

Fill both blanks to build a notification with a small icon and a title.

Android Kotlin
val notification = Notification.Builder(context, "channel_id_01")
    .setSmallIcon([1])
    .setContentTitle([2])
    .build()
Drag options to blanks, or click blank then click option'
AR.drawable.ic_notification
B"New Message"
CR.layout.notification_layout
D"Notification Title"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a layout resource instead of a drawable for the icon.
Not using quotes around the title string.
5fill in blank
hard

Fill all three blanks to send the notification with ID 1001.

Android Kotlin
val [3] = Notification.Builder(context, "channel_id_01")
    .setSmallIcon(R.drawable.ic_notification)
    .setContentTitle("Hello")
    .build()

notificationManager.[1](1001, [2])
Drag options to blanks, or click blank then click option'
Anotify
Bnotification
CsendNotification
DnotificationBuilder
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong method name like sendNotification.
Passing the wrong variable as the notification.
Using inconsistent variable names.