我正在使用Kotlin和Android Studio尝试在一个测试应用中推送通知。 我遵循了Android Developers网站上有关如何创建通知的说明 (https://developer.android.com/training/notify-user/build-notification),但似乎做错了什么,我的通知没有显示在任何地方。 这是我的代码:
val intent = Intent(context, Profile::class.java)
val pendingIntent = PendingIntent.getActivity(this.context, 0, intent, 0);
val builder = NotificationCompat.Builder(this.context)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_MAX)
builder.setContentIntent(pendingIntent).setAutoCancel(true)
val mNotificationManager = message.context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
with(mNotificationManager) {
notify(123, builder.build())
我真的不知道我缺少什么,所以任何帮助都将不胜感激。