代码改变世界

信息提醒-Notification

2011-04-22 11:17  bitfairyland  阅读(268)  评论(0编辑  收藏  举报
1.创建NotificationManager 对象获得系统提供的服务getSystemService(NOTIFICATION_SERVICE)
2.创建Notification 对象设置信息内容
3.把Notification 对象传给android框架显示
 
 
protected void showNotification () {
NotificationManager barManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
 
Notification barMsg = new Notification(
R.drawable.icon_128,
"稼筁舘",
System.currentTimeMillis()
);
barMsg.defaults |= Notification.DEFAULT_SOUND;
//barMsg.defaults |= Notification.DEFAULT_ALL;
 
PendingIntent contentIntent = PendingIntent.getActivity(
this,
0,
new Intent(this, Bmi.class),
PendingIntent.FLAG_UPDATE_CURRENT);
 
barMsg.setLatestEventInfo(
Report.this,
"眤 BMI 筁蔼",
"硄菏服",
contentIntent);
 
barManager.notify(0, barMsg);
}