1

For my app, I use one notification ID as to not clutter the Notifications Menu of a user. Each of my notifications have Ticker Text. When there are no notifications from my app, and the user gets notified, the ticker text displays. When a notification already exists, and is merely updated, the ticker text does not get displayed.

I made a work around which is very hacky, where I cancel the notification before I notify, but this ultimately causes a very obvious lag with vibrations.

Currently how I have notifications happening:

    mBuilder.setSmallIcon(R.drawable.actionbar_logo)
            .setContentTitle(extras.getString("title"))
            .setContentText(extras.getString("summary"))
            .setAutoCancel(true)
            .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(extras.getString("extended_text"))
            )
            .setLights(Color.WHITE, NOTIF_LIGHT_INTERVAL, NOTIF_LIGHT_INTERVAL)
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("mainActivityNotification", true);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 424242, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(contentIntent);

    final Notification notification = mBuilder.build();
    notification.tickerText = extras.getString("title") + "\n" +
                              extras.getString("summary") + "\n" +
                              extras.getString("post_body");

    mNotificationManager.notify(GATE_NOTIFICATION_ID, notification);
David
  • 7,028
  • 10
  • 48
  • 95
  • You probably are messing up with `PendingIntent`s, but for anyone to be able to answer the question you should provide the minimum relevant code. – ozbek Jan 22 '15 at 09:58
  • 2
    Looking at the answer here http://stackoverflow.com/a/16435330/2841101. It says you have to use the same builder next time. And using that builder you just update the tickertext. – Dhir Pratap Jan 23 '15 at 09:03

1 Answers1

3

Android does not display the ticker text again if it is the same as before.

You may use setTicker API of Notification.Builder class instead of constructing ticker text using Notification object, as Notification.Builder has been added to make it easier to construct Notifications.

And if your intentions is to re-display the same ticker text(from previously posted notification), then just add this Line :

mNotificationManager.notify(GATE_NOTIFICATION_ID, mBuilder.build());

After you posted your first notification.

So, your complete code looks like as below:

mBuilder.setSmallIcon(R.drawable.actionbar_logo)
            .setContentTitle(extras.getString("title"))
            .setContentText(extras.getString("summary"))
            .setAutoCancel(true)
            .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(extras.getString("extended_text"))
            )     //consider using setTicker here
            .setLights(Color.WHITE, NOTIF_LIGHT_INTERVAL, NOTIF_LIGHT_INTERVAL)
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("mainActivityNotification", true);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 424242, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(contentIntent);

    final Notification notification = mBuilder.build();

    //consider using setTicker of Notification.Builder
    notification.tickerText = extras.getString("title") + "\n" +
                              extras.getString("summary") + "\n" +
                              extras.getString("post_body");

    mNotificationManager.notify(GATE_NOTIFICATION_ID, notification);
    //second time onward, add your changed content like setContentText, setTicker etc.
    mNotificationManager.notify(GATE_NOTIFICATION_ID, mBuilder.build());
AADProgramming
  • 6,077
  • 11
  • 38
  • 58