zoukankan      html  css  js  c++  java
  • 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/
    欢迎任何形式的转载,未经作者同意,请保留此段声明!

  • 相关阅读:
    Scala 基础语法(二)
    Scala 基础语法(一)
    Scala 概述+scala安装教程+IDEA创建scala工程
    树链剖分【p2590】[ZJOI2008]树的统计
    树链剖分【p1505】[国家集训队]旅游
    状压DP【p1896】[SCOI2005]互不侵犯
    树链剖分【P3833】 [SHOI2012]魔法树
    KMP【UVA1328】 Period
    Trie树【UVA11362】Phone List
    线段树【p2801】教主的魔法
  • 原文地址:https://www.cnblogs.com/linlf03/p/2964951.html
Copyright © 2011-2022 走看看