알림 배지 수정
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 8.0(API 수준 26)부터 연결된 앱에 활성 알림이 있는 경우 런처 아이콘에 알림 배지(알림 표시 점이라고도 함)가 표시됩니다. 사용자는 앱 아이콘을 길게 터치하여 그림 1과 같이 앱 바로가기와 함께 알림을 표시할 수 있습니다.
이러한 점은 기본적으로 알림 표시 점을 지원하는 런처 앱에 표시되며 앱에서 처리할 작업은 없습니다. 하지만, 알림 표시 점을 표시하지 않거나 표시되는 알림을 정확히 제어하고 싶은 경우도 있습니다.
그림 1. 알림 배지 및 길게 터치 메뉴
배지 사용 중지
배지가 알림에 적합하지 않은 경우 NotificationChannel
객체에서 setShowBadge(false)
를 호출하여 채널별로 배지를 사용 중지할 수 있습니다.
예를 들어 다음과 같은 경우 알림 배지를 사용 중지할 수 있습니다.
- 진행 중인 알림: 이미지 처리, 미디어 재생 컨트롤, 현재 탐색 안내 등 대부분의 진행 중인 알림에는 배지가 무의미합니다.
- 캘린더 리마인더: 현재 발생한 이벤트에는 배지를 사용하지 마세요.
- 시계 또는 경보 이벤트: 현재 경보와 관련된 알림에는 배지를 사용하지 마세요.
다음 샘플 코드는 알림 채널의 배지를 숨기는 방법을 보여줍니다.
Kotlin
val id = "my_channel_01"
val name = getString(R.string.channel_name)
val descriptionText = getString(R.string.channel_description)
val importance = NotificationManager.IMPORTANCE_LOW
val mChannel = NotificationChannel(id, name, importance).apply {
description = descriptionText
setShowBadge(false)
}
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(mChannel)
자바
String id = "my_channel_01";
CharSequence name = getString(R.string.channel_name);
String description = getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
mChannel.setShowBadge(false);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(mChannel);
맞춤 알림 수 설정
기본적으로 알림이 발생하면 그림 1과 같이 길게 터치 메뉴에 표시되는 숫자가 1씩 증가하지만 앱에서 이 숫자를 재정의할 수 있습니다. 예를 들어 하나의 알림을 사용하여 여러 개의 새 메시지를 나타내지만 이 숫자로 새 메시지의 총 수를 나타내고 싶은 경우 숫자를 재정의하면 유용합니다.
맞춤 숫자를 설정하려면 다음과 같이 알림에서 setNumber()
를 호출합니다.
Kotlin
var notification = NotificationCompat.Builder(this@MainActivity, CHANNEL_ID)
.setContentTitle("New Messages")
.setContentText("You've received 3 new messages.")
.setSmallIcon(R.drawable.ic_notify_status)
.setNumber(messageCount)
.build()
자바
Notification notification = new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
.setContentTitle("New Messages")
.setContentText("You've received 3 new messages.")
.setSmallIcon(R.drawable.ic_notify_status)
.setNumber(messageCount)
.build();
알림의 길게 터치 메뉴 아이콘 수정
길게 터치 메뉴에는 알림과 연관된 큰 아이콘이나 작은 아이콘이 표시됩니다(있는 경우). 기본적으로 시스템에는 큰 아이콘이 표시되지만 Notification.Builder.setBadgeIconType()
를 호출하고 BADGE_ICON_SMALL
상수를 전달하여 작은 아이콘을 표시할 수도 있습니다.
Kotlin
var notification = NotificationCompat.Builder(this@MainActivity, CHANNEL_ID)
.setContentTitle("New Messages")
.setContentText("You've received 3 new messages.")
.setSmallIcon(R.drawable.ic_notify_status)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
.build()
자바
Notification notification = new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
.setContentTitle("New Messages")
.setContentText("You've received 3 new messages.")
.setSmallIcon(R.drawable.ic_notify_status)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
.build();
중복 바로가기 숨기기
앱에서 앱 바로가기를 복제하는 알림을 만드는 경우 setShortcutId()
를 호출하여 알림이 활성화되어 있는 동안 바로가기를 일시적으로 숨길 수 있습니다.
알림을 사용하는 추가 샘플 코드는 SociaLite 샘플 앱을 참고하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Modify a notification badge\n\nStarting with Android 8.0 (API level 26), notification badges---also known as\nnotification dots---appear on a launcher icon when the associated app has an\nactive notification. Users can\ntouch \\& hold the app icon to reveal the notifications, along with any\n[app shortcuts](/guide/topics/ui/shortcuts), as shown in\nfigure 1.\n\nThese dots appear by default in launcher apps that support them, and there's\nnothing your app needs to do. However, there might be situations in which you\ndon't want the to notification dot to appear or you want to control exactly\nwhich notifications appear there.\n\n\n**Figure 1.** Notification badges and the touch \\& hold menu.\n\n\u003cbr /\u003e\n\nDisable badging\n---------------\n\nThere are cases where badges don't make sense for your notifications, so you\ncan disable them on a per-channel basis by calling\n[`setShowBadge(false)`](/reference/android/app/NotificationChannel#setShowBadge(boolean))\non your [`NotificationChannel`](/reference/android/app/NotificationChannel)\nobject.\n\nFor example, you might want to disable notification badges in the following\nsituations:\n\n- Ongoing notifications: most ongoing notifications, such as image processing, media playback controls, or current navigation instructions, don't make sense as a badge.\n- Calendar reminders: avoid badging events occurring at the current time.\n- Clock or alarm events: avoid badging notifications related to current alarms.\n\nThe following sample code demonstrates how to hide badges for\na notification channel: \n\n### Kotlin\n\n```kotlin\nval id = \"my_channel_01\"\nval name = getString(R.string.channel_name)\nval descriptionText = getString(R.string.channel_description)\nval importance = NotificationManager.IMPORTANCE_LOW\nval mChannel = NotificationChannel(id, name, importance).apply {\n description = descriptionText\n setShowBadge(false)\n}\nval notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager\nnotificationManager.createNotificationChannel(mChannel)\n```\n\n### Java\n\n```java\nString id = \"my_channel_01\";\nCharSequence name = getString(R.string.channel_name);\nString description = getString(R.string.channel_description);\nint importance = NotificationManager.IMPORTANCE_LOW;\nNotificationChannel mChannel = new NotificationChannel(id, name, importance);\nmChannel.setDescription(description);\nmChannel.setShowBadge(false);\n\nNotificationManager notificationManager =\n (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);\nnotificationManager.createNotificationChannel(mChannel);\n```\n\nSet custom notification count\n-----------------------------\n\nBy default, each notification increments a number displayed on the touch \\& hold\nmenu, as shown in figure 1, but you can override this number for your app.\nFor example, this might be useful if you're using just one notification to\nrepresent multiple new messages but want the count to represent the\nnumber of total new messages.\n\nTo set a custom number, call\n[`setNumber()`](/reference/androidx/core/app/NotificationCompat.Builder#setNumber(int))\non the notification, as shown here: \n\n### Kotlin\n\n```kotlin\nvar notification = NotificationCompat.Builder(this@MainActivity, CHANNEL_ID)\n .setContentTitle(\"New Messages\")\n .setContentText(\"You've received 3 new messages.\")\n .setSmallIcon(R.drawable.ic_notify_status)\n .setNumber(messageCount)\n .build()\n```\n\n### Java\n\n```java\nNotification notification = new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)\n .setContentTitle(\"New Messages\")\n .setContentText(\"You've received 3 new messages.\")\n .setSmallIcon(R.drawable.ic_notify_status)\n .setNumber(messageCount)\n .build();\n```\n\nModify a notification's touch \\& hold menu icon\n-----------------------------------------------\n\nThe touch \\& hold menu displays the large or small icon associated with a\nnotification if available. By default, the system displays the large icon, but\nyou can call\n[`Notification.Builder.setBadgeIconType()`](/reference/androidx/core/app/NotificationCompat.Builder#setBadgeIconType(int))\nand pass in the [`BADGE_ICON_SMALL`](/reference/androidx/core/app/NotificationCompat#BADGE_ICON_SMALL())\nconstant to display the small icon. \n\n### Kotlin\n\n```kotlin\nvar notification = NotificationCompat.Builder(this@MainActivity, CHANNEL_ID)\n .setContentTitle(\"New Messages\")\n .setContentText(\"You've received 3 new messages.\")\n .setSmallIcon(R.drawable.ic_notify_status)\n .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)\n .build()\n```\n\n### Java\n\n```java\nNotification notification = new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)\n .setContentTitle(\"New Messages\")\n .setContentText(\"You've received 3 new messages.\")\n .setSmallIcon(R.drawable.ic_notify_status)\n .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)\n .build();\n```\n\nHide a duplicate shortcut\n-------------------------\n\nIf your app creates a notification that duplicates an [app shortcut](/guide/topics/ui/shortcuts), you can\ntemporarily hide the shortcut while the notification is active by calling\n[`setShortcutId()`](/reference/androidx/core/app/NotificationCompat.Builder#setShortcutId(java.lang.String)).\n\nFor more sample code that uses notifications, see the [SociaLite sample app](https://github.com/android/socialite)."]]