我正在尝试向用户显示通知,但是某些操作无效。没有记录错误消息,并且应用程序继续运行。我正在从我的应用程序的主活动中调用此代码。
val notificationId = buildNotificationId(messageId)
val builder: NotificationCompat.Builder = NotificationCompat.Builder(this,"123")
val mNotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val pendingIntent = Intent(this, MainPage::class.java)
val notifyPendingIntent = PendingIntent.getActivity(this, 0, pendingIntent, PendingIntent.FLAG_UPDATE_CURRENT)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
pendingIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
builder.setSmallIcon(R.drawable.icon)
.setLargeIcon(BitmapFactory.decodeResource(applicationContext.resources, R.drawable.icon))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentTitle(title)
.setAutoCancel(true)
.setStyle(NotificationCompat.BigTextStyle().bigText(message))
.setOnlyAlertOnce(true)
builder.setContentIntent(notifyPendingIntent)
mNotificationManager.notify(notificationId, builder.build())
}
谢谢,我忘了创建频道!