根据文档,我已经在应用程序中进行了更改,使用context.startForegroundService(Intent)
在后台启动服务,然后像以前一样在服务中调用startForeground
。
NotificationCompat.Builder notification = new
NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.icon)
.setContentText("Content")
.setOngoing(true)
.setContentInfo("Info")
.setContentTitle("Title");
startForeground(1, notification.build());
在Android N设备上,此代码可以正确地显示通知,但在Android O设备上,它不会显示通知,只会显示新的“正在后台运行……点击以获取有关电池和数据使用情况的更多详细信息”。
是否缺少某些内容才能在Android O上正确显示通知?