通知栏Notification使用

来源:互联网 发布:java 数据字典表设计 编辑:程序博客网 时间:2024/05/19 16:50
                                NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);Notification mNotification = new Notification(R.drawable.icon_cat, "你有新的消息了", System.currentTimeMillis());PendingIntent contentIntent = PendingIntent.getActivity(context, 0, getIntent(), 0);mNotification.setLatestEventInfo(context, "天气预报", "晴转多云", contentIntent);mNotificationManager.notify(R.drawable.icon_dog, mNotification);

1、通过getSystemService(NOTIFICATION_SERVICE) 获取一个NotificationManager 对象

2、新建通知栏出现在顶端

3、新建系统维护的PendingIntent对象

4、设置出现在下拉栏消息

5、使用NotificationManager 把通知展示 第一个参数为Notification 唯一标识



mNotification2.flags = Notification.FLAG_ONGOING_EVENT; //设置notification 为常驻通知

cancelall()  //清空所有通知

0 0