文档详情

Android Notification详细解读.doc

发布:2017-12-12约6.13千字共7页下载文档
文本预览下载声明
Android Notification详细解读 NotificationManager(通知管理器): NotificationManager负责通知用户事件的发生. NotificationManager有三个公共方法: 1. cancel(int id) 取消以前显示的一个通知.假如是一个短暂的通知,试图将隐藏,假如是一个持久的通知,将从状态条中移走. 2. cancelAll() 取消以前显示的所有通知. 3. notify(int id, Notification notification) 把通知持久的发送到状态条上. Java代码 //初始化NotificationManager: NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Java代码 //初始化NotificationManager: NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); //初始化NotificationManager: NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification代表着一个通知. Notification的属性: audioStreamType 当声音响起时,所用的音频流的类型 contentIntent 当通知条目被点击,就执行这个被设置的Intent. contentView 当通知被显示在状态条上的时候,同时这个被设置的视图被显示. defaults 指定哪个值要被设置成默认的. deleteIntent 当用户点击Clear All Notifications按钮区删除所有的通知的时候,这个被设置的Intent被执行. icon 状态条所用的图片. iconLevel 假如状态条的图片有几个级别,就设置这里. ledARGB LED灯的颜色. ledOffMS LED关闭时的闪光时间(以毫秒计算) ledOnMS LED开始时的闪光时间(以毫秒计算) number 这个通知代表事件的号码 sound 通知的声音 tickerText 通知被显示在状态条时,所显示的信息 vibrate 振动模式. when 通知的时间戳. Notification的公共方法: describeContents() Describe the kinds of special objects contained in this Parcelables marshalled representation. setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence Android Notification介绍 ? Notification就是在桌面的状态通知栏。这主要涉及三个主要类: ? Notification:设置通知的各个属性。 ? NotificationManager:负责发送通知和取消通知 ? Notification.Builder:Notification内之类,创建Notification对象。非常方便的控制所有的flags,同时构建Notification的风格。 ? 主要作用: ? 1.创建一个状态条图标。 ? 2.在扩展的状态条窗口中显示额外的信息(和启动一个Intent)。 ? 3.闪灯或LED。 ? 4.电话震动。 ? 5.发出听得见的警告声(铃声,保存的声音文件)。 ? Notification是看不见的程序组件(Broadcast Receiver,Service和不活跃的Activity)警示用户有需要注意的事件发生的最好途径 ? 下面主要介绍这三个类: ? 一、NotificationManager ? 这个类是这三个类中最简单的。主要负责将Notification在状态显示出来和取消。主要包括5个函数:void cancel(int id),void cancel(String tag, int id),void cancelAll(),void notify(int id, Notification notification),notify(String tag, int id, Notification notification) ? 看看这五个函数就知道这个类的作用了。但是在初始化对象的时候要注意: ? Notification
显示全部
相似文档