0

我正在尝试使用PagesStacksAndroid Wear SDK预览。没有Wear代码,通知显示正常,而如果我使用Wear特定代码,我无法收到通知,无论是在电话上还是在Wear Emulator. 我已经阅读了 10 次代码,我想我需要一双新的眼睛来捕捉错误。

此代码应在电话上Notification为每个Tracker(发送 a 的外部设备Message)创建一个未读Message的列表(使用InboxStyle)。在Wear它上面应该堆叠多个Notification按 s 分组的 s ,为每个未读Tracker添加一个。PageMessage

  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());
}
4

1 回答 1

1

对于堆叠通知,您可以创建notify多个通知

  • 对于您希望在 Wear 上显示的每个堆叠通知,您notify拨打过的通知setGroup(trackerGroupId)
  • 对于您希望在手机/平板电脑上显示的摘要通知,您拨打notify过的通知setGroup(trackerGroupid, WearableNotifications.GROUP_ORDER_SUMMARY)

我认为您的问题是您必须有一个摘要通知,任何通知才能出现在任一设备上。

于 2014-06-20T16:18:03.897 回答