通知欄(Notification、NotificationManager)

狀態欄是系統服務的一種。所以我們使用它時,必須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);

 

 

 

 

 

運行效果:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章