기기홈 noti는 푸시를 받았을때 뱃지 카운트를 달 수 있다.
이 뱃지 카운트를 수정하고 싶을때는
//수정하고 싶은 숫자를 넣고 호출 0은 안된다 noti를 제거해야함
private fun updateHomeBadgeCount(badgeCount:Int) {
Intent("android.intent.action.BADGE_COUNT_UPDATE")
.putExtra("badge_count", badgeCount)
.putExtra("badge_count_package_name", packageName)
.putExtra("badge_count_class_name", getLauncherClassName(this))
.run { sendBroadcast(this) }
}
private fun getLauncherClassName(context: Context): String? {
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_LAUNCHER)
intent.setPackage(context.applicationContext.packageName)
val resolveInfoList =
context.applicationContext.packageManager.queryIntentActivities(intent, 0)
return if (resolveInfoList != null && resolveInfoList.size > 0) {
resolveInfoList[0].activityInfo.name
} else ""
}
뱃지 카운트를 제거 하고 싶을때는 아래 코드를 활용
private fun clearNotification() {
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(1); // cancel(알림 특정 id)//
// 이전에 있던 모든 Notification 알림 제거
notificationManager.cancelAll();
}
'Programing > Spring Boot' 카테고리의 다른 글
| 단위 테스트와 통합 테스트, 언제 어떤 걸 써야 할까? (0) | 2025.04.07 |
|---|---|
| Spring Boot 다국어(i18n) 처리 및 MessageSource 활용 (0) | 2023.12.26 |
| 오류) Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. (0) | 2023.08.28 |
| 동시성 문제 해결 - 비관적 락 (Pessimistic Lock) (0) | 2023.08.03 |
| 코틀린 Querydsl Pageble Sort 동적 정렬 쉽게 사용하기 + 유틸화 (0) | 2023.07.13 |