狀態欄是系統服務的一種。所以我們使用它時,必須getSystemService()!
NotificationManager是“容器”,PendingIntent是“調度者”,而Notification是具體的一個通知。
其主要代碼如下:
NotificationManager notiManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notiInst = new Notification(
R.drawable.ic_launcher, "This is notify 2012-09-12",
System.currentTimeMillis());
PendingIntent pendIntent = PendingIntent.getActivity(
this, 0, new Intent(this, MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT);
notiInst.setLatestEventInfo(this, "Notify", "Notify 01", pendIntent);
notiManager.notify(0, notiInst);
運行效果: