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,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值