android 磨损中的 Whatsapp 点赞通知
Whatsapp like notification in android wear
我需要在 android wear like whatsapp 中实现通知,其中每个对话都是一个列表,向右滑动允许用户回复相应的对话。我尝试从 android 开发人员示例中堆叠,但它只按原样显示消息。我怎样才能像在 whatsapp 中那样设置多于 1 条消息和相应的操作?
编辑:
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);
你基本上遗漏了三个不同的东西:
- 您没有在
NotificationBuilder
上呼叫 setGroup("GROP_NAME")
- 属于同一组的通知必须有不同的ID。如果您始终使用相同的 ID 通知,
NOTIFICATION_ID
在您的情况下,ste 堆叠将不起作用
- 您希望每个通知都有不同的
replyPendingIntent
,否则您的待定意向将参考最后通知的通知。不是硬编码 0
,而是为每个通知传递不同的值。
其他看起来不错,
我需要在 android wear like whatsapp 中实现通知,其中每个对话都是一个列表,向右滑动允许用户回复相应的对话。我尝试从 android 开发人员示例中堆叠,但它只按原样显示消息。我怎样才能像在 whatsapp 中那样设置多于 1 条消息和相应的操作?
编辑:
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);
你基本上遗漏了三个不同的东西:
- 您没有在
NotificationBuilder
上呼叫 - 属于同一组的通知必须有不同的ID。如果您始终使用相同的 ID 通知,
NOTIFICATION_ID
在您的情况下,ste 堆叠将不起作用 - 您希望每个通知都有不同的
replyPendingIntent
,否则您的待定意向将参考最后通知的通知。不是硬编码0
,而是为每个通知传递不同的值。
setGroup("GROP_NAME")
其他看起来不错,