Bookmark profile

시중에 돌아다니는 코드를 보면 다음과 같다.

private fun showPushNotification(context: Context) {
    // Notification 생성
    val channelId = "my_channel_id"
    val notificationBuilder = NotificationCompat.Builder(context, channelId)
        .setSmallIcon(android.R.drawable.ic_dialog_info)
        .setContentTitle("새로운 알림")
        .setContentText("알림 내용입니다.")
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .setAutoCancel(true)

    // NotificationManager를 통해 NotificationChannel 생성 (Android 8.0 이상)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val channel = NotificationChannel(
            channelId,
            "My Channel",
            NotificationManager.IMPORTANCE_DEFAULT
        )
        val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        notificationManager.createNotificationChannel(channel)
    }

    // NotificationManager를 통해 Notification 표시
    val notificationManagerCompat = NotificationManagerCompat.from(context)
    notificationManagerCompat.notify(1, notificationBuilder.build())
}

NotificationManager.IMPORTANCE_DEFAULT 이런 옵션을 추가하면 된다고 한다.

그런데 안된다.

와… 왜이러지 …

알고보니 이 옵션은, 앱을 삭제 후 다시 실행해야만 적용되는 옵션이었다. 왜냐하면 안드로이드 채널은 앱이 설치되어있고 채널이 이미 생성되어있는 한, 그대로 옵션을 유지하기 때문이다!