Android通知未显示在API 26上
我最近将我的应用程序更新为API 26,甚至在不更改代码的情况下,通知也不再起作用.
I recently updated my app to API 26, and notifications are no longer working, without even changing the code.
val notification = NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Title")
.setContentText("Text")
.build()
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(1, notification)
为什么不起作用?我不知道对API进行了一些更改吗?
Why isn't it working? Was there some change to the API that I'm not aware of?
来自文档:
Android O引入了通知通道,以提供一个统一的系统来帮助用户管理通知. 定位到Android O时,您必须实现一个或多个通知通道以向用户显示通知.如果不定位到Android O,则应用程序在运行时的行为与在Android 7.0上的行为相同在Android O设备上.
Android O introduces notification channels to provide a unified system to help users manage notifications. When you target Android O, you must implement one or more notification channels to display notifications to your users. If you don't target Android O, your apps behave the same as they do on Android 7.0 when running on Android O devices.
(强调已添加)
您似乎没有将此Notification
与渠道相关联.
You do not seem to be associating this Notification
with a channel.