我需要在Android Wear中实现通知,例如在whatsapp中,其中每个对话都是一个列表,并且向右滑动可让用户回复相应的对话。我尝试从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);
您实际上缺少了三件事:
setGroup("GROP_NAME")
你的NotificationBuilder
NOTIFICATION_ID
在这种情况下,ste堆栈将无法工作replyPendingIntent
每个通知都各不相同,否则您的待处理意图将指的是上一次通知的通知。不用硬编码0
,而是为每个通知传递一个不同的值。其余的看起来不错,
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句