Showing Different Notification on Android Device and Pebble

321 views Asked by At

When I use WhatsApp or Telegram and receive N messages, the notification on Android will show "N new messages" (and it can be expanded).

On Android

  • Telegram shows notification with contentText "7 new messages" on Android. I have achieved this successfully.

However, on my Pebble Time, the last notification is the string of the last message, not "7 new messages".

Telegram On Pebble

  • On Pebble, it shows the 7th (last) message (the censored part is phone number). This is what I want.

I am trying to develop similar feature but have not succeeded. The notification on my Android displays correctly ("N new messages") but on Pebble Time, it's identical (also "N new messages", I want it to be the Nth message).

My App On Pebble

  • My app on Pebble. This is NOT what I want.

I have tried to call .notify twice (one contains "N new messages" and the other contains last message) and immediately .cancel the latter but Pebble Time only shows the first one.

If I don't call .cancel on the second notification, my Pebble will show what I want BUT there will be 2 notifications on both Android and Pebble (which I don't want).

How do I achieve similar feature like WhatsApp and Telegram?

Update:

This is the snippet I use (I have used different notification ID)

NotificationCompat.Builder nb = new NotificationCompat.Builder();
...
nb.setContentText("2 new messages");
notificationManager.notify(1, nb.build());

nb.setContentText("B");
notificationManager.notify(2, nb.build());
notificationManager.cancel(2);
1

There are 1 answers

7
asdcvf On

Because you use same id for two notification item. you can try with different id for each show notification item.

From Android docs: https://developer.android.com/reference/android/app/NotificationManager.html#notify(int, android.app.Notification)

id: An identifier for this notification unique within your application.