android6-4 Exercise 1: Channel and notification ============================================ import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context const val REMINDER_CHANNEL_ID = "note_reminders" fun createNotificationChannels(context: Context) { // Channels exist on Android 8.0+ (API 26); minSdk 26 or higher needs no version check val channel = NotificationChannel( REMINDER_CHANNEL_ID, "Note reminders", NotificationManager.IMPORTANCE_DEFAULT ).apply { description = "Reminders you set on a note" } context.getSystemService(NotificationManager::class.java).createNotificationChannel(channel) } // In NotesApplication.onCreate(): createNotificationChannels(this) // (docs: create the channel at app start; creating an existing channel does nothing) import android.Manifest import android.app.PendingIntent import android.content.Intent import android.content.pm.PackageManager import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.core.content.ContextCompat fun showReminder(context: Context, noteId: Long, text: String) { val openApp = PendingIntent.getActivity( context, noteId.toInt(), Intent(context, MainActivity::class.java).putExtra("noteId", noteId), PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT ) val notification = NotificationCompat.Builder(context, REMINDER_CHANNEL_ID) .setSmallIcon(R.drawable.ic_stat_note) .setContentTitle("Note reminder") .setContentText(text) .setContentIntent(openApp) .setAutoCancel(true) .build() // notify() is annotated as needing POST_NOTIFICATIONS (docs), so check first val allowed = Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED if (allowed) { NotificationManagerCompat.from(context).notify(noteId.toInt(), notification) } } Debug button: Button(onClick = { showReminder(context, 1L, "Test") }) { Text("Notify now") }. Report: on Android 13+ without the permission nothing appears (docs: denial blocks notifications); after granting it does. Older Android needs no permission. The channel "Note reminders" appears under the app's notification settings (general knowledge; menu names vary). Code unrun.