我試圖顯示一個正在進行的通知,而不顯示最初的股票行情文本。我能夠在構造股票文本設置爲空,以獲得與老式通知這方面的工作:隱藏使用Notification.Builder的通知中的股票代碼文本
mNotification = new Notification(R.drawable.ic_stat_playing, null, System.currentTimeMillis());
然而,我注意到,實例化一個通知,現在這種方式已經過時,而且使用Notification.Builder的建議改爲。但是,我不能得到通知現在顯示沒有股票的文字,甚至當我設置股票文本到空:
Notification.Builder builder = new Notification.Builder(this);
CharSequence contentText = "contentText here";
Intent launchIntent = new Intent(this, MainActivity.class);
// The PendingIntent to launch our activity if the user selects this
// notification
PendingIntent contentIntent = PendingIntent.getActivity(this, -1,
launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_stat_playing)
.setLargeIcon(null)
.setTicker(null)
.setOnlyAlertOnce(true)
.setWhen(System.currentTimeMillis())
.setContentTitle(contentTitle)
.setOngoing(true)
.setContentText(contentText);
mNotification = builder.getNotification();
startForeground(NOTIFICATION_ID, mNotification);
難道只是無法關閉股票顯示新Notification.Builder?是的,這很不幸,因爲我不能從已棄用的代碼進行更新。
編輯 - 終於工作的代碼:
mNotification = builder.getNotification();
mNotification.tickerView = null;
startForeground(NOTIFICATION_ID, mNotification);
這是正確的方法(即'setTicker(null)')。上述代碼會發生什麼?無論如何,股票都顯示出來了?什麼操作系統,設備等? – dsandler
感謝您的回覆。是的,使用上面的代碼,無論如何都會顯示代碼。我正在使用運行Android 4.0.3的Asus Transformer TF101平板電腦和運行Android 3.2的10.1英寸Galaxy Tab進行測試。 – inky