我想在Android通知中顯示時間戳,就像Android Design Guidelines suggest.(請參閱第一張快照,「12:03 PM」是我想要的!)。如何在Honeycomb +設備的Android通知中顯示時間戳?
我嘗試了許多不同的方式,我認爲setWhen
會這樣做,但它似乎隻影響通知托盤中的排序。任何想法如何實現?
見下面我的代碼:
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_notify)
.setLargeIcon(largeIcon)
.setTicker(text)
.setNumber(unreadCount)
.setWhen((new Date()).getTime())
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(text)
.setDefaults(Notification.DEFAULT_VIBRATE);
notificationManager.notify(NOTIFICATION_ID, builder.getNotification());
我不想使用自定義佈局的通知。
它似乎沒有工作。 'setContentInfo'將顯示第2行的字符串,替換'number'。我想要的是第1行右邊的'when'和第2行右邊的'number'。 有趣的是,他們使用GTalk和Calendar通知作爲示例,這些應用程序都沒有顯示我的時間戳Galaxy Nexus(4.0.2)。 – tdevaux