您的位置:首页 > 移动开发 > Android开发

菜鸟Android学习之路27——notification

2013-12-25 16:21 423 查看
代码:

 final int NOTIFYID_1=123;

 final int NOTIFYID_2=134;

 

 @Override

 protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

  final NotificationManager notification =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

  Button button1=(Button)findViewById(R.id.button1);

  button1.setOnClickListener(new OnClickListener() {

   

   @Override

   public void onClick(View v) { 

//    THE first notification

    Notification notify=new Notification();

    notify.icon=R.drawable.img06;

    notify.tickerText="the first time";

    notify.when=System.currentTimeMillis();

    notify.defaults =Notification.DEFAULT_ALL;

    notify.setLatestEventInfo(MainActivity.this, "no title", "every i can have a little stpe", null);

    notification.notify(NOTIFYID_1, notify);

//    the second notification

    Notification notify_1=new Notification(R.drawable.img06," the second notify",System.currentTimeMillis());

    notify_1.flags|=Notification.FLAG_AUTO_CANCEL;

    Intent intent=new Intent(MainActivity.this,ContentActivity.class);

   }

  });

  Button button2 =(Button)findViewById(R.id.button2);

  button2.setOnClickListener(new OnClickListener() {

   

   @Override

   public void onClick(View v) {

    // TODO Auto-generated method stub

    notification.cancelAll();

   }

  });

效果:




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: