android之notification

1 简介:notification就是通知,它基本上不占用屏幕的空间,当用户下拉的时候展示信息.
2 用法: 1)首先获取系统服务:
manger =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
2)在监听事件里面添加内容 ,有点类似于对话框.
Notification.Builder builder = new Builder(MainActivity.this);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setTicker(“新消息”);
builder.setContentTitle(“通知”);
builder.setContentText(“你的微信有新的版本需要更新”);
builder.setDefaults(Notification.DEFAULT_ALL);//通知的方式,震动,铃声
manger.notify(0x01, builder.build());//通知号,方便清除
3)清楚通知:
manger.cancel(0x01);
3 实例:
android之notification4 这个获取系统服务这块,我还是不太懂…
如果写完之后有很多的横线,是安卓的最低版本太低了.在androidmainfest.xml中修改大一些就好了.
android之notification