我尝试使用Pages
预览中的Stacks
和Android Wear SDK
。如果没有Wear
代码,通知就会显示正常,而如果我使用Wear
特定代码,则无法通过电话或Wear Emulator
收到通知。我已经完成了10次代码,我想我需要一双新眼睛来捕捉错误。
此代码应在手机上为每个Notification
(发送Tracker
的外部设备)创建Message
,其中包含未读Message
的列表(使用InboxStyle
)。在Wear
上,它应该按Notification
分组多个Tracker
,为每个未读Page
添加Message
。
public static void showNewMessagesNotif(Context context, Tracker tracker, List<Message> messages) {
String trackerName = tracker.getName() + " - " + tracker.getPhoneNumber();
String contentTitle = context.getResources().getQuantityString(R.plurals.notif_new_messages, messages.size(), messages.size());
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + tracker.getPhoneNumber()));
PendingIntent callPendingIntent = PendingIntent.getActivity(context, 0, callIntent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_action_location_searching)
.setContentTitle(contentTitle)
.setContentText(trackerName)
.setAutoCancel(true)
.addAction(R.drawable.ic_action_call, context.getString(R.string.action_call), callPendingIntent);
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle(contentTitle);
// Moves events into the big view
for (Message message : messages) {
inboxStyle.addLine(message.getText());
}
inboxStyle.setSummaryText(trackerName);
// Moves the big view style object into the notification object.
mBuilder.setStyle(inboxStyle);
mBuilder.setContentIntent(getNotificationIntent(context, tracker));
// Issue the notification here.
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(context);
int notifId = (int) (NEW_MESSAGE_NOTIF_BASE_ID + tracker.getRowId());
//Android Wear Notifications
List<Notification> wearPages = new ArrayList<Notification>();
for (Message message : messages) {
NotificationCompat.BigTextStyle extraPageStyle = new NotificationCompat.BigTextStyle();
extraPageStyle.setBigContentTitle(message.getText())
.bigText(message.getAddress());
Notification extraPageNotification = new NotificationCompat.Builder(context)
.setStyle(extraPageStyle)
.build();
wearPages.add(extraPageNotification);
}
WearableNotifications.Builder wearNotificationBuilder =
new WearableNotifications.Builder(mBuilder)
.setHintHideIcon(true)
.setGroup(GROUP_BY_TRACKER).addPages(wearPages);
// mId allows you to update the notification later on.
notificationManager.notify(notifId, wearNotificationBuilder.build());
}
答案 0 :(得分:1)
对于stacking notifications,您可以创建并notify
多个通知
notify
您已拨打setGroup(trackerGroupId)
的通知notify
您已拨打setGroup(trackerGroupid, WearableNotifications.GROUP_ORDER_SUMMARY)
的通知我认为您的问题是必须有任何通知显示在任一设备上的摘要通知。