菜鸟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();
}
});
效果:
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();
}
});
效果:
相关文章推荐
- Android开发学习之路--Notification之初体验
- android <初级篇> 第一个工程Hello World ! ——菜鸟的学习之路
- Android开发学习之路--Notification之初体验
- 菜鸟Android学习之路28——AlertDialog(4)显示带多个选列表项的对话框
- Android开发学习之路--Notification之初体验
- 菜鸟Android学习之路28——AlertDialog(3)带多个单选项的列表框
- 菜鸟Android学习之路19——星级评分条
- 【Android菜鸟学习之路】环境搭建问题-修改AVD Path
- 菜鸟Android学习之路13——图片按钮
- android菜鸟学习笔记27----Fragment的简单使用
- android <初级篇> 界面布局<一> ——菜鸟的学习之路
- android菜鸟的学习求职之路
- 菜鸟Android学习之路29——AlertDialog
- android <初级篇> 发送短信(调用已有接口)——菜鸟的学习之路
- 菜鸟Android学习之路16——自动补全文本
- 菜鸟Android学习之路28——AlertDialog(1)带取消、确认按钮对话框
- 菜鸟Android学习之路26——消息提示框和对话框
- Android菜鸟学习之路——Activity生命周期
- 菜鸟Android学习之路22——网格视图