Я добавил канал в NotificationManager и Builder, но моя активность все еще не открывается при нажатии на уведомление - PullRequest
0 голосов
/ 06 апреля 2020

Ниже приведен мой код:

    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())
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...