NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "新消息", System.currentTimeMillis());
//采用默认声音
notification.defaults |= Notification.DEFAULT_SOUND;
//使用默认的灯光
notification.defaults |= Notification.DEFAULT_LIGHTS;
//通知被点击后,自动消失
notification.flags |= Notification.FLAG_AUTO_CANCEL;
//点击'Clear'时,不清楚该通知(QQ的通知无法清除,就是用的这个)
notification.flags |= Notification.FLAG_NO_CLEAR;
// 点击清除按钮不会清除消息通知,可以用来表示在正在运行
notification.flags |= Notification.FLAG_ONGOING_EVENT;
Intent appIntent = new Intent(context, EventActivity.class);
appIntent.addCategory(Intent.CATEGORY_LAUNCHER);
appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, appIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// notification.setLatestEventInfo(context, title, desc, contentIntent);
notification.setLatestEventInfo(context, "新消息", "“伊斯兰国”攻势不停 美向库尔德人提供武器", contentIntent);
notificationManager.notify(messageNotificationID, notification);