我最近将我的应用更新为API 26,并且通知不再有效,甚至没有更改代码.
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变化?
解决方法
从
the documentation开始:
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.
(重点补充)
您似乎没有将此通知与频道相关联.