Android Notication的使用

一、Android Notication的使用

private  void  sendNotification() {
     // TODO Auto-generated method stub
     NotificationManager manager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE);
     Notification notification = new  Notification();
     notification.icon = R.drawable.ic_launcher;
     notification.tickerText = "I am in the state bar!" ;
     notification.audioStreamType = android.media.AudioManager.ADJUST_LOWER;
     
     Intent intent = new  Intent( this , secondActivity. class  );
     PendingIntent pendingIntent = PendingIntent.getActivity( this ,
             0, intent, PendingIntent.FLAG_ONE_SHOT);
     
     notification.setLatestEventInfo( this , "Content Title" , "Content" , pendingIntent);
     manager.notify(1,notification);
             
}

代码解释:

1:获取NotificationManager:

NotificationManager m_NotificationManager=(NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);

2:定义一个Notification:

  Notification  m_Notification=new Notification();

3:设置Notification的各种属性:

//设置通知图标

m_Notification.icon=R.drawable.icon;               

  //当我们点击通知时显示的内容

m_Notification.tickerText="Button1 通知内容.....";                                

//通知时发出默认声音

m_Notification.defaults=Notification.DEFAULT_SOUND;

//设置通知显示参数

Intent   m_Intent=new Intent(NotificationDemo.this,DesActivity.class);      

PendingIntent m_PendingIntent=PendingIntent.getActivity(NotificationDemo.this, 0, m_Intent, 0);

m_Notification.setLatestEventInfo(NotificationDemo.this, "Button1", "Button1通知",m_PendingIntent );

//开始执行通知

m_NotificationManager.notify(0,m_Notification);

4:既然增加能同样能删除。

  m_NotificationManager.cancel(0);   

  这个0是一个ID号,和notify第一个参数0一样。

 

二、Android Notification自定义布局实现

http://blog.csdn.net/nature_day/article/details/8659714



本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2013/03/17/2964951.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

微信关注我们

原文链接:https://yq.aliyun.com/articles/359921

转载内容版权归作者及来源网站所有!

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

相关文章

发表评论

资源下载

更多资源
优质分享Android(本站安卓app)

优质分享Android(本站安卓app)

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario,低调大师唯一一个Java游戏作品

Mario,低调大师唯一一个Java游戏作品

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Apache Tomcat7、8、9(Java Web服务器)

Apache Tomcat7、8、9(Java Web服务器)

Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。

Java Development Kit(Java开发工具)

Java Development Kit(Java开发工具)

JDK是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具。