android– 使用API​​ 26的NotificationCompat

android– 使用API​​ 26的NotificationCompat,第1张

概述我没有看到任何有关如何将NotificationCompat与AndroidO的通知频道一起使用的信息我确实看到了一个新的构造函数,它接受了一个channelId,但是如何获取Compat通知并在NotificationChannel中使用它,因为createNotificationChannel需要一个NotificationChannel对象解决方法:仅当API>

我没有看到任何有关如何将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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1103540.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存