//创建old通知 设置status Icon 和tickerText
notification = new Notification(R.drawable.ic_launcher, "我是old通知",
System.currentTimeMillis());
Intent intent = new Intent(this, OtherActivity.class);
//点击通知栏中的通知后进行加载Intent并执行intent的action将Activity跳转
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
//通知在通知栏中的设置信息
notification.setLatestEventInfo(this, "hillo!!", "你好!欢迎光临",
contentIntent);
//获取通知manager对象
notifiManager = (NotificationManager) this
.getSystemService(NOTIFICATION_SERVICE);
//manager将通知显示 如需要点击后删除通知 需Manager对象调用cancle(通知标识符id) cancleAll()或者Builder.setAutoCancle();
notifiManager.notify(100, notification);
//android4.1后notification
Intent intent = new Intent(this, OtherActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
notifiBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher).setTicker("new通知来了")
.setContentTitle("hello,我是title")
.setContentText("这是contentText")
.setContentIntent(contentIntent)
// 设置通知的声音,震动,Led灯
//震动需要添加用户权限 android.permission.VIBRATE
.setDefaults(Notification.DEFAULT_ALL);
notification=notifiBuilder.build();
notifiManager.notify(200,notification);