Ниже приведен мой код:
private val CHANNEL_ID = "Test"
private val CHANNEL_NAME = "Test_Name"
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
CHANNEL_ID,
CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT
)
channel.description = "Description"
notificationManager.createNotificationChannel(channel)
}
val intent = Intent(
context,
WebViewActivity::class.java
)
val contentIntent =
PendingIntent.getActivity(this, 2, intent, PendingIntent.FLAG_ONE_SHOT)
val builder: NotificationCompat.Builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setSound(null)
.setChannelId(CHANNEL_ID)
.setContentIntent(contentIntent)
notificationManager.notify(1, builder.build())