Android 使用notification.Builder在通知中隐藏股票代码文本

Android 使用notification.Builder在通知中隐藏股票代码文本,android,notifications,ticker,Android,Notifications,Ticker,我正在尝试显示正在进行的通知,而不显示初始的ticker文本。通过在构造函数中将ticker text设置为null,我可以在使用旧样式通知时实现这一点: mNotification = new Notification(R.drawable.ic_stat_playing, null, System.currentTimeMillis()); 但是,我注意到,现在不推荐使用这种方式实例化通知,而推荐使用Notification.Builder。但是,即使我将ticker text设置为nul

我正在尝试显示正在进行的通知,而不显示初始的ticker文本。通过在构造函数中将ticker text设置为null,我可以在使用旧样式通知时实现这一点:

mNotification = new Notification(R.drawable.ic_stat_playing, null, System.currentTimeMillis());
但是,我注意到,现在不推荐使用这种方式实例化通知,而推荐使用Notification.Builder。但是,即使我将ticker text设置为null,我现在也无法在没有ticker text的情况下显示通知:

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
,只需将其省略如下:

builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_stat_playing)
.setLargeIcon(null)
.setOnlyAlertOnce(true)                 
.setWhen(System.currentTimeMillis())
.setContentTitle(contentTitle)
.setOngoing(true)
.setContentText(contentText);

尝试将tickerView设置为生成器之后的null。那对我来说很好 代码如下:

Notification notif = builder.build();
notif.tickerView = null;
mNotificationManager.notify(id, notif);

这是正确的方法(即,
setTicker(null)
)。上面的代码会发生什么?股票行情显示了吗?什么操作系统、设备等?感谢您的回复。是的,有了上面的代码,股票代码还是会显示出来。我正在运行安卓4.0.3的华硕Transformer TF101平板电脑和运行安卓3.2的10.1英寸Galaxy平板电脑上进行测试。谢谢,终于为我解决了这个问题!谢谢,我也有同样的行为,只有这样我才能把它修好!