드디어 UDEMY 왕초보 강좌의 1장의 마지막 강좌
NOTIFICATION...
생각보다 복잡하니, 일단 만들어 놓고, 복붙으로 쓰는게 좋을것 같다.
button.setOnClickListener { view ->
var not = getNotificationBuilder("channel1", "1st channel")
not.setTicker("Ticker")
not.setSmallIcon(android.R.drawable.ic_menu_search)
var bitmap = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher)
not.setLargeIcon(bitmap)
not.setNumber(100)
not.setAutoCancel(true)
not.setContentTitle("Content Title")
not.setContentText("Content Text")
var notification = not.build()
var mng = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
mng.notify(10, notification)
}
}
fun getNotificationBuilder(id:String, name:String) : NotificationCompat.Builder {
var not : NotificationCompat.Builder? = null
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
var manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
var channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH)
// channel.enableLights(true)
// channel.lightColor = Color.RED
// channel.enableVibration(true)
manager.createNotificationChannel(channel)
not = NotificationCompat.Builder(this, id)
}else{
not = NotificationCompat.Builder(this)
}
return not
}
OS버전에 따라 두가지 형태의 NOTIFICATION 빌더를 세팅하고, 적용한다는 것이 핵심.
뭐가 이리 복잡해.. ;
'Dead Code > DEPRECATED-KOTLIN' 카테고리의 다른 글
[코틀린코드연습장] Activity 전환(Anko) (0) | 2019.01.01 |
---|---|
[코틀린코드연습장] RecycleView 뭐에다 쓰는건가 (0) | 2018.12.27 |
[코틀린코드연습장] 옵션메뉴에 붙어있는 검색창 사용하기 (0) | 2018.12.24 |
[코틀린코드연습장] 다이얼로그 - 날짜/시간 입력 다이얼로그 (0) | 2018.12.21 |
[코틀린코드연습장] viewPager 생성하기 (0) | 2018.12.10 |
[코틀린코드연습장] 기본 다이얼로그 (0) | 2018.10.18 |
[코틀린코드연습장] 커스텀 토스트 (0) | 2018.10.16 |
[코틀린코드연습장] 예전부터 궁금했던, 토스트 띄우기 (0) | 2018.10.02 |
[코틀린코드연습장] Options Menu 활성화하기 (0) | 2018.09.29 |
[코틀린코드연습장] ContextMenu from Udemy (0) | 2018.09.19 |