Android -- NotificationManager and Notification学习笔记

NotificationManager(通知管理器):
NotificationManager负责通知用户事件的发生.
NotificationManager有三个公共方法:
1. cancel(int id) 取消以前显示的一个通知.假如是一个短暂的通知,试图将隐藏,假如是一个持久的通知,将从状态条中移走.
2. cancelAll() 取消以前显示的所有通知.
3. notify(int id, Notification notification) 把通知持久的发送到状态条上.

//初始化NotificationManager:
NotificationManager nm =
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);



Notification代表着一个通知.
Notification的属性:
[color=red]audioStreamType [/color] 当声音响起时,所用的音频流的类型
[color=red]contentIntent[/color] 当通知条目被点击,就执行这个被设置的Intent.
[color=red]contentView[/color] 当通知被显示在状态条上的时候,同时这个被设置的视图被显示.
[color=red]defaults[/color] 指定哪个值要被设置成默认的.
[color=red]deleteIntent[/color] 当用户点击"Clear All Notifications"按钮区删除所有的通知的时候,这个被设置的Intent被执行.
[color=red]icon[/color] 状态条所用的图片.
[color=red]iconLevel[/color] 假如状态条的图片有几个级别,就设置这里.
[color=red]ledARGB[/color] LED灯的颜色.
[color=red]ledOffMS[/color] LED关闭时的闪光时间(以毫秒计算)
[color=red]ledOnMS[/color] LED开始时的闪光时间(以毫秒计算)
[color=red]number[/color] 这个通知代表事件的号码
[color=red]sound[/color] 通知的声音
[color=red]tickerText[/color] 通知被显示在状态条时,所显示的信息
[color=red]vibrate[/color] 振动模式.
[color=red]when[/color] 通知的时间戳.

Notification的公共方法:
describeContents() Describe the kinds of special objects contained in this Parcelable's marshalled representation.
setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) 设置Notification留言条的参数
writeToParcel(Parcel parcel, int flags) Flatten this notification from a parcel.
toString() …………….

将Notification发送到状态条上:
Notification notification = new Notification();
Notification的设置过程……..
nm.notify(0, notification); //发送到状态条上
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值