notification 을 표시할 때 아래와 같이 상단에 펼쳐진 채로 보여지는 걸 heads up notification 이라고 한다.
여러가지 설정해주어야 할 것이 많지만 중요한건 setFullScreenIntent 를 해주어야 한다는 것이다. 해당 메서드를 이용하면
여기서는 heads up notification 으로 보여주기 위한 방법까지만 알아보고 디바이스가 꺼져 있을 때 acticity 화면으로 띄워주길 원하면 Android Alarm 만들기 여기를 참고하길 바란다.
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
val channelId = "Download"
val notificationId = Math.random().toInt()
val manager = NotificationManagerCompat.from(context)
val channel = NotificationChannelCompat
.Builder(channelId, NotificationManagerCompat.IMPORTANCE_HIGH)
.setName("File Download")
.build()
manager.createNotificationChannel(channel)
val intent = Intent(context, DialogActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
val builder = NotificationCompat.Builder(context, channel.id)
.setSmallIcon(icon)
.setTicker("Downloading...")
.setContentTitle("Downloading...")
.setPriority(NotificationManagerCompat.IMPORTANCE_HIGH)
.setAutoCancel(false)
.setFullScreenIntent(pendingIntent, true)
manager.notify(notificationId, builder.build())