//显示通知栏图标
private void showNotification() {
NotificationManager notificationManager = (NotificationManager)
this.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
// 定义Notification的各种属性
Notification notification =new Notification(R.drawable.logo,
"YQ 正在运行", System.currentTimeMillis());
notification.flags |= Notification.FLAG_ONGOING_EVENT; //加入通知栏的"Ongoing"中
notification.flags |= Notification.FLAG_NO_CLEAR; //点击了通知栏中的"清除通知"后不清除
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults = Notification.DEFAULT_LIGHTS;
// 设置通知的事件消息
Intent notificationIntent =new Intent(this, MainActivity.class);
PendingIntent contentItent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(this,
"YQ", // 通知栏标题
"Android 即时通信工具 YQ", // 通知栏内容
contentItent); // 点击该通知后要跳转的Activity
// 把Notification传递给NotificationManager,id为0
notificationManager.notify(0, notification);
}原文:http://blog.csdn.net/fangchao3652/article/details/20866913