Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- 코틀린
- sqlite
- onLayout
- recyclerview
- Coroutine
- Behavior
- 알림
- BOJ
- DataBinding
- CustomView
- hilt
- Navigation
- CollapsingToolbarLayout
- CoordinatorLayout
- room
- 알고리즘
- 안드로이드
- LiveData
- Algorithm
- onMeasure
- ViewModel
- Android
- lifecycle
- 백준
- HTTP
- AppBarLayout
- notification
- kotlin
- activity
- View
Archives
- Today
- Total
개발일지
Android in A..Z - Notification (Extend) 본문
확장형 알림
기존의 알림보다 훨씬 많은 알림을 제공하기 위해 확장형 알림을 사용할 수 있다.
코드
@Singleton
class ExtendNotificationManager @Inject constructor(
@ApplicationContext
private val context: Context
) {
companion object {
private const val CHANNEL_ID_IMPORTANCE_HIGH = "com.taetae98.notification.EXTEND.IMPORTANCE_HIGH"
private const val CHANNEL_ID_IMPORTANCE_LOW = "com.taetae98.notification.EXTEND.IMPORTANCE_LOW"
private const val CHANNEL_NAME = "Extend"
private const val CHANNEL_DESCRIPTION = "Extend Notification"
}
private val manager by lazy { context.getSystemService(NotificationManager::class.java) }
fun imageNotify(message: Message, bitmap: Bitmap) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(CHANNEL_ID_IMPORTANCE_HIGH, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH)
}
val notification = NotificationCompat.Builder(context, CHANNEL_ID_IMPORTANCE_HIGH)
.setSmallIcon(R.drawable.ic_android)
.setContentTitle(message.title)
.setContentText(message.message)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setStyle(
NotificationCompat.BigPictureStyle()
.bigPicture(bitmap)
)
.build()
manager.notify(message.id, notification)
}
fun progressNotify(message: Message) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(CHANNEL_ID_IMPORTANCE_HIGH, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH)
createNotificationChannel(CHANNEL_ID_IMPORTANCE_LOW, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW)
}
CoroutineScope(Dispatchers.IO).launch {
repeat(101) {
val notification = NotificationCompat.Builder(context, if(it == 100) CHANNEL_ID_IMPORTANCE_HIGH else CHANNEL_ID_IMPORTANCE_LOW)
.setPriority(if (it == 100) NotificationCompat.PRIORITY_MAX else NotificationCompat.PRIORITY_MIN)
.setSmallIcon(R.drawable.ic_android)
.setContentTitle(message.title)
.setContentText(message.message)
.setProgress(100, it, it <= 10)
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
.build()
manager.notify(message.id, notification)
delay(100L)
}
}
}
@RequiresApi(Build.VERSION_CODES.O)
private fun createNotificationChannel(id: String, name: String, importance: Int) {
val channel = NotificationChannel(id, name, importance).apply {
description = CHANNEL_DESCRIPTION
}
manager.createNotificationChannel(channel)
}
}
setStyle을 통해서 기본으로 제공하는 Template을 사용할 수 있다.
Git
https://github.com/KangTaeJong98/Example/tree/main/Android/Notification
'Android (안드로이드) > Notification' 카테고리의 다른 글
Android in A..Z - Notification (Custom) (0) | 2021.07.15 |
---|---|
Android in A..Z - Notification (Group) (0) | 2021.07.15 |
Android in A..Z - Notification (Action) (0) | 2021.07.15 |
Android in A..Z - Notification (기본) (0) | 2021.07.15 |
Comments