状态栏是系统服务的一种。所以我们使用它时,必须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);
运行效果: