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

  • 相关阅读:
    面向对象介绍
    常用模块2
    常用模块1
    常用模块3
    模块导入以及常用模块
    模块介绍
    Astra: Apache Cassandra的未来是云原生
    麦格理银行借助DataStax Enterprise (DSE) 驱动数字化转型
    Apache Cassandra使用报告2020
    比较Apache Cassandra的压力测试工具
  • 原文地址:https://www.cnblogs.com/linlf03/p/2964951.html
Copyright © 2011-2022 走看看