2

最初のティッカー テキストを表示せずに進行中の通知を表示しようとしています。コンストラクターでティッカー テキストを null に設定することで、古いスタイルの Notification でこれを機能させることができました。

mNotification = new Notification(R.drawable.ic_stat_playing, null, System.currentTimeMillis());

ただし、この方法で Notification をインスタンス化することは推奨されなくなり、代わりに Notification.Builder の使用が推奨されることに気付きました。ただし、ティッカー テキストを null に設定しても、ティッカー テキストなしで通知を表示することはできません。

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);
4

2 に答える 2

3

含める必要はまったくありません.setTicker。次のように省略してください。

builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_stat_playing)
.setLargeIcon(null)
.setOnlyAlertOnce(true)                 
.setWhen(System.currentTimeMillis())
.setContentTitle(contentTitle)
.setOngoing(true)
.setContentText(contentText);
于 2012-10-18T05:01:06.083 に答える
2

ビルダーの後に tickerView を null に設定してみてください。それは私にとってはうまくいきます:

Notification notif = builder.build();
notif.tickerView = null;
mNotificationManager.notify(id, notif);
于 2013-05-30T07:13:03.393 に答える