




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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, charsequenceandroid 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)看看这五个函数就知道这个类的作用了。但是在初始化对象的时候要注意:notificationmanager nm = (notificationmanager) getsystemservice(notification_service);二、notification设置这个类主要是设置notification的相关属性。初始化notification n = new notification();notification里面有很多属性下面选择几个常用的介绍一下icon 这个是设置通知的图标。像qq的小企鹅sound 这个是设置来通知时的提示音。tickertext 设置提示的文字。vibrate 来通知时振动。when 设置来通知时的时间flag 这个很有意思是设置通知在状态栏显示的方式。它的值可以设置为虾米这些值:flag_no_clear 将flag设置为这个属性那么通知栏的那个清楚按钮就不会出现flag_ongoing_event 将flag设置为这个属性那么通知就会像qq一样一直在状态栏显示default_all 将所有属性设置为默认default_sound 将提示声音设置为默认default_vibrate 将震动设置为默认三、notification.builder这个类一般用于管理notification,动态的设置notification的一些属性。即用set来设置。也没啥好说的。看一个例子:这个例子还需要在xml中添加两个按钮public class main extends activity private button sendbtn , cancelbtn; private notification n; private notificationmanager nm; /notification的标示id private static final int id = 1; override public void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.main); /实例化按钮 sendbtn = (button)this.findviewbyid(r.id.sendbtn); cancelbtn = (button)this.findviewbyid(r.id.cancelbtn); /获取notificationmanager实例 string service = notification_service; nm = (notificationmanager)this.getsystemservice(service); /实例化notification n = new notification(); /设置显示图标,该图标会在状态栏显示 int icon = r.drawable.icon; /设置显示提示信息,该信息也会在状态栏显示 string tickertext = test notifaction; /显示时间 long when = system.currenttimemillis(); n.icon = icon; n.tickertext = tickertext; n.when = when; n.flags = notification.flag_no_clear; n.flags = notification.flag_ongoing_event; /为按钮添加监听器 sendbtn.setonclicklistener(sendclicklistener); cancelbtn.setonclicklistener(cancelclicklistener); private onclicklistener sendclicklistener = new onclicklistener() override public void onclick(view v) /实例化intent intent intent = new intent(main.this, main.class); /获取pendingintent pendingintent pi = pendingintent.getactivity(main.this, 0, intent, 0); /设置事件信息 n.setlatesteventinfo(main.this, my title, my content, pi); /发出通知 nm.notify(id, n); ;private onclicklistener cancelclicklistener = new onclicklistener() override public void onclick(view v) nm.cancel(id); ;android notification 事件nm=(notificationmjava代码 1. nm=(notificationmanager)context.getsystemservice(context.notification_service);2. notificationnotification=newnotification(android.r.drawable.stat_sys_download,itemname,system3. .currenttimemillis();4. intentnotificationintent=newintent(context,installactivity.class);5. notificationintent.putextra(hasdownloaded,false);6. notificationintent.putextra(oranotificationid,oranotificationid);7. pendingintentcontentintent=pendingintent.getactivity(context,8. this.oranotificationid,9. notificationintent,pendingintent.flag_cancel_current);10. /notification.contentintent=contentintent;11. 12. notification.setlatesteventinfo(context,null,null,13. contentintent);14. notification.contentview=newremoteviews(context.getpackagename(),15. r.layout.imediadotbiz_process);16. notification.contentview.settextviewtext(r.id.dotbizimedia_core_tv_downing,itemname);17. notification.contentview.setprogressbar(r.id.dotbizimedia_core_pb_downing,100,0,false);18. nm.notify(oranotificationid,notification);19. 启动多个notification后,设置每个notification
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年食品科学与工程专业综合知识考核试题及答案
- Aromatase-IN-5-生命科学试剂-MCE
- 2025年人力资源管理政策与实务试题及答案
- 2025年监会与财经法规专业资格考试试题及答案
- 2025年家庭教育与儿童心理发展专业知识考试试卷及答案
- 2025年海洋科学专业研究生入学考试题及答案
- 2025年公共卫生管理硕士考试试题及答案
- 爱的礼物我家的宠物狗写物作文(7篇)
- 一年级写人作文我的妹妹300字(12篇)
- 我的语文老师从点滴细节中感受温暖(6篇)
- 互联网与营销创新智慧树知到期末考试答案章节答案2024年华东师范大学
- 云南开放大学实-用写作离线作业1-5
- 四川省成都市温江县2023-2024学年八下物理期末监测试题及答案解析
- 内科学(肾脏-内分泌-血液)智慧树知到期末考试答案章节答案2024年温州医科大学
- 食品安全与日常饮食智慧树知到期末考试答案章节答案2024年中国农业大学
- 100以内进退位加减法口算题每天60道
- MOOC 嵌入式软件设计-大连理工大学 中国大学慕课答案
- 永久基本农田储备区划定技术方案
- 医疗销售经验技巧分享
- 大气组成与垂直分层(简洁版)
- 钢铁企业环保培训课件
评论
0/150
提交评论