- 在 Activity 中创建
- 在 BoardCast 中创建
- 在 Service 中创建
- 管理 Notification
NotificationManager manager = (NotificationManager) Context.getSystemService(Context.NOTIFICATION_SERVICE);
- 构造 Notification 对象
通过
NotificationCompat.Builder
构造
Notification notification = new NotificationCompat.Builder(context).build();
或者
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle("This is content title")
.setContentText("This is content Text")
.setWhen(System.currentTimeMillis()) //被通知的时间
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.large_icon)
.build();
- 显示通知 调用 NotificationManager 的 notifiy() 方法. 参数1 id 参数2 Notification 对象
manager.notify(1,notificaton)