Reputation: 1137
I need to achieve notification in android wear like in whatsapp where each conversation is a list and sliding to the right allows the user to reply to the respective conversation. I tried stacking from the android developers example but it only displays messages as is. How could I set more than 1 message and respective action like in whatsapp?
Edit:
NotificationCompat.WearableExtender wearOptions =
new NotificationCompat.WearableExtender()
.setHintHideIcon(true);
String replyLabel = mXmppConnectionService.getResources().getString(R.string.wear_reply);
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
.setLabel(replyLabel)
.build();
Intent replyIntent = new Intent(mXmppConnectionService, XmppConnectionService.class);
PendingIntent replyPendingIntent =
PendingIntent.getActivity(mXmppConnectionService, 0, replyIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.mipmap.ic_launcher,
"reply to", replyPendingIntent)
.addRemoteInput(remoteInput)
.build();
final Builder mBuilder;
mBuilder.setDefaults(0);
mBuilder.setSmallIcon(R.drawable.ic_notification);
mBuilder.setPriority(getPriority());
mBuilder.setDeleteIntent(createDeleteIntent());
mBuilder.setLights(0xff00FF00, 2000, 3000)
.extend(wearOptions)
.extend(new NotificationCompat.WearableExtender().addAction(action));
final Notification notification = mBuilder.build();
notificationManager.notify(NOTIFICATION_ID, notification);
Upvotes: 0
Views: 482
Reputation: 157457
you are missing essentially three different things:
setGroup("GROP_NAME")
on your NotificationBuilder
NOTIFICATION_ID
in your case, ste stacking will not workreplyPendingIntent
for each notification, otherwise your pending intent will refer to the last notification notified. Instead of hard-coding 0
, pass a different value for each notification. The rest looks good,
Upvotes: 1