奥利奥模拟器上没有显示通知

我一直试图在奥利奥模拟器上显示一个简单的通知。 奇怪的是,我什么都看不到。

让我们消除明显的答案:我试图检查应用程序的通知,我尝试了通知和NotificationCompat路径。 我尝试了有或没有频道,我尝试过或没有团体。

代码是基本的(是的,我使用Kotlin,但很容易理解):

class MainActivity : Activity() { var id = 0 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val button:View = findViewById(R.id.button) button.setOnClickListener(this::onAddNotification) } private fun onAddNotification(v: View) { id++ val builder = Notification.Builder(this).setSmallIcon(R.drawable.ic_notifications_none) .setContentTitle("Content #$id").setContentText("Content text for $id") val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.notify(id, builder.build()) } } 

毋庸置疑,它是在奥利奥前完美的代码。 另一方面,Gmail和Google地图会在该模拟器上显示通知。 任何我可能已经忘记了?

谢谢

谷歌说:当你的目标是Android 8.0(API级别26)时,你必须实现一个或多个通知渠道来向用户显示通知。 如果您不是针对Android 8.0(API级别26),而是在运行Android 8.0(API级别26)的设备上使用您的应用,那么您的应用的行为与在运行Android 7.1(API级别25)或更低级别的设备上的行为相同。

https://developer.android.com/guide/topics/ui/notifiers/notifications.html

正如Tim Castelijns所述:如果您使用API​​26,则必须使用通道

请记住, NotificationCompat没有正确处理 (至2017年9月4日),因此您的选择是:

  • 使用API​​级别25或更低版本
  • 使用渠道。 请注意,Google不赞成API 26上的Builder(context)构造函数。出于一个非常好的原因。