代码:
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();
}
});
效果: