Whatsapp喜欢在android中发布通知

时间:2015-06-14 14:21:15

标签: android wear-os

我需要在whatsapp中实现android的通知,其中每个会话都是一个列表,向右滑动允许用户回复相应的会话。我尝试从Android开发人员示例堆叠,但它只按原样显示消息。如何在whatsapp中设置多条消息和相应的操作?

编辑:

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

1 个答案:

答案 0 :(得分:1)

你基本上缺少三件事:

  1. 您没有在setGroup("GROP_NAME")
  2. 上致电NotificationBuilder
  3. 属于同一组的通知必须具有不同的ID。如果您始终使用相同的ID通知NOTIFICATION_ID,则无法使用堆叠
  4. 您希望每个通知都有不同的replyPendingIntent,否则您的待处理意图将引用最后通知的通知。而不是硬编码0,为每个通知传递不同的值。
  5. 其余的看起来不错,

相关问题