【问题标题】:What differences between NotificationManager and NotificationManagerCompat?NotificationManager 和 NotificationManagerCompat 有什么区别?
【发布时间】:2019-03-05 15:23:47
【问题描述】:

我可以这样创建通知:

 NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 if (notificationManager != null) {
     notificationManager.notify(NOTIFICATION_ID, notification);
 }

等等:

 NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(MainActivity.this);
 notificationManagerCompat.notify(NOTIFICATION_ID, notification);

那么,这些方式有什么区别呢?

【问题讨论】:

标签: java android push-notification android-notifications


【解决方案1】:

NotificationManagerCompatNotificationManager 的兼容性库,具有旧平台的回退功能。

我鼓励你看看NotificationManagerCompat 类,因为有很多不同的调整。

通常NotificationManagerCompat 中的几乎所有函数都调用NotificationManager 中的兼容函数。

例如函数NotificationManagerCompat.notify() 检查标志EXTRA_USE_SIDE_CHANNEL。如果是false - 该函数只调用NotificationManager.notify()。如果设置为true,则发布的通知应使用侧通道进行传递,而不是使用通知管理器(需要支持侧通道通知的最大 sdk 构建版本是 API 19)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-02
    • 2011-12-12
    • 2010-09-16
    • 2012-03-14
    • 2012-02-06
    • 2011-02-25
    • 2011-11-22
    相关资源
    最近更新 更多