我一直试图在奥利奥模拟器上显示一个简单的通知。奇怪的是,我什么都看不到。奥利奥模拟器上没有显示通知
让我们消除明显的答案:我试图检查应用程序的通知,我尝试了Notifications和NotificationCompat路径。我尝试了或不带频道,我尝试过或不加分组。
代码为基础(是的,我用科特林但它很容易理解):
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地图会在该模拟器上显示通知。 任何我可能已经忘记的东西?
感谢
你*** ***必须使用渠道 –
嗯,没错的。要么是“还没有使用API 26”。 NotificationCompat尚不支持它。 Uncool,Google,非常酷! –