我一直試圖在奧利奧模擬器上顯示一個簡單的通知。奇怪的是,我什麼都看不到。奧利奧模擬器上沒有顯示通知
讓我們消除明顯的答案:我試圖檢查應用程序的通知,我嘗試了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,非常酷! –