12 java android push-notification android-notifications
我能够创建通知,以便:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(NOTIFICATION_ID, notification);
}
Run Code Online (Sandbox Code Playgroud)
所以:
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(MainActivity.this);
notificationManagerCompat.notify(NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)
那么,这些方式有什么区别呢?
NotificationManagerCompat是一个兼容NotificationManager旧平台的后备库。
我鼓励你看看课程,NotificationManagerCompat因为有很多不同的调整。
一般来说,几乎所有函数都NotificationManagerCompat调用NotificationManager.
例如,函数NotificationManagerCompat.notify()检查标志EXTRA_USE_SIDE_CHANNEL。如果是false- 该函数只需调用NotificationManager.notify(). 如果设置为true,则发布的通知应使用侧通道进行传递,而不是使用通知管理器(需要支持侧通道通知的最大 sdk 构建版本为 API 19)。
| 归档时间: |
|
| 查看次数: |
2874 次 |
| 最近记录: |