繁体   English   中英

Whatsapp像Android Wear中的通知

[英]Whatsapp like notification in android wear

我需要像在whatsapp中那样在Android Wear中实现通知,其中每个对话都是一个列表,向右滑动可让用户回复相应的对话。 我尝试从android开发人员示例进行堆叠,但仅按原样显示消息。 如何设置超过1条消息以及类似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. 您没有在NotificationBuilder上调用setGroup("GROP_NAME")
  2. 属于同一组的通知必须具有不同的ID。 如果您始终使用相同的ID( NOTIFICATION_ID ,则Ste stack无效
  3. 您需要为每个通知使用不同的replyPendingIntent ,否则您的待处理意图将引用最后通知的通知。 而不是硬编码0 ,而是为每个通知传递不同的值。

其余的看起来不错,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM