
原因是升级到Android O 版本后,该方法被以下方法取代:
NotificationCompat.Builder(Context context, String channelId)
即新增一个String参数即可,因此,简单notification可以直接加一个String参数:
NotificationManager manager=
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification =new NotificationCompat.Builder(this,"default")
.setContentTitle("测试notification")
.setContentText("This is content text")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher_round)
.build();
manager.notify(1,notification);
而channelId的实际作用是将notification进行分类,如设置不同优先级等。也可使用NotificationChannel.getId()设置channelId,欲获取 NotificationChannel的详细知识请参考以下链接:
关于NotificationChannel的详细知识
本文介绍了如何在Android O版本中适配Notification,包括使用NotificationCompat.Builder的新方法,并解释了channelId的作用及其设置方法。
过时,失效&spm=1001.2101.3001.5002&articleId=79661045&d=1&t=3&u=e55ee349c9df432e8024f6d4737a88a2)
573

被折叠的 条评论
为什么被折叠?



