
我没有看到任何有关如何将NotificationCompat与Android O的通知频道一起使用的信息
我确实看到了一个新的构造函数,它接受了一个channelID,但是如何获取Compat通知并在NotificationChannel中使用它,因为createNotificationChannel需要一个NotificationChannel对象
解决方法:
仅当API> = 26时才创建NotificationChannel
public voID initChannels(Context context) { if (Build.VERSION.SDK_INT < 26) { return; } notificationmanager notificationmanager = (notificationmanager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel channel = new NotificationChannel("default", "Channel name", notificationmanager.importANCE_DEFAulT); channel.setDescription("Channel description"); notificationmanager.createNotificationChannel(channel);}然后使用:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, "default");因此,您的通知适用于API 26(带通道)和下面(无).
总结以上是内存溢出为你收集整理的android – 使用API 26的NotificationCompat全部内容,希望文章能够帮你解决android – 使用API 26的NotificationCompat所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)