2010-08-25 63 views
-1

我要在通知欄(帶有USB連接模式的下拉菜單等)中列出通知列表?Android通知

+4

請與清楚你要什麼。這是非常模糊的 – the100rabh 2010-08-25 17:17:04

+0

請訪問[此鏈接更新的答案](http://stackoverflow.com/a/35913469/2826147)。 – 2016-03-10 10:15:12

回答

4

拜託老兄,這是標準的東西:

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

String ns = Context.NOTIFICATION_SERVICE; 
NotificationManager mNotificationManager = 
             (NotificationManager) getSystemService(ns); 

int icon = android.R.drawable.ic_media_play; 
CharSequence ticketText = "Now - Playing"; 
long when = System.currentTimeMillis(); 

Notification notification = new Notification(icon, ticketText, when); 

Context context = getApplicationContext(); 
CharSequence contentTitle = "Now"; 
CharSequence contentText = "Session"; 
Intent notificationIntent = new Intent(this, PlayTrack.class); 
notificationIntent.addFlags(Notification.FLAG_ONGOING_EVENT); 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
             notificationIntent, 0); 

notification.setLatestEventInfo(context, contentTitle,contentText,contentIntent); 

mNotificationManager.notify(CONFIDENCE_NOW_ID, notification);