in WearAccessibilityApp/Wearable/src/main/java/com/example/android/wearable/wear/wearaccessibilityapp/MessagingIntentService.java [64:118]
private void handleActionReply(CharSequence replyCharSequence) {
Log.d(TAG, "handleActionReply(): " + replyCharSequence);
if (replyCharSequence != null) {
// TODO: Asynchronously save your message to Database and servers.
/*
* You have two options for updating your notification (this class uses approach #2):
*
* 1. Use a new NotificationCompatBuilder to create the Notification. This approach
* requires you to get *ALL* the information that existed in the previous
* Notification (and updates) and pass it to the builder. This is the approach used in
* the MainActivity.
*
* 2. Use the original NotificationCompatBuilder to create the Notification. This
* approach requires you to store a reference to the original builder. The benefit is
* you only need the new/updated information. In our case, the reply from the user
* which we already have here.
*
* IMPORTANT NOTE: You shouldn't save/modify the resulting Notification object using
* its member variables and/or legacy APIs. If you want to retain anything from update
* to update, retain the Builder as option 2 outlines.
*/
// Retrieves NotificationCompat.Builder used to create initial Notification
NotificationCompat.Builder notificationCompatBuilder =
GlobalNotificationBuilder.getNotificationCompatBuilderInstance();
// Recreate builder from persistent state if app process is killed
if (notificationCompatBuilder == null) {
// Note: New builder set globally in the method
notificationCompatBuilder = recreateBuilderWithMessagingStyle();
}
// Since we are adding to the MessagingStyle, we need to first retrieve the
// current MessagingStyle from the Notification itself.
Notification notification = notificationCompatBuilder.build();
MessagingStyle messagingStyle =
NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(
notification);
// Add new message to the MessagingStyle. Set last parameter to null for responses
// from user.
messagingStyle.addMessage(replyCharSequence, System.currentTimeMillis(), (Person) null);
// Updates the Notification
notification = notificationCompatBuilder.setStyle(messagingStyle).build();
// Pushes out the updated Notification
NotificationManagerCompat notificationManagerCompat =
NotificationManagerCompat.from(getApplicationContext());
notificationManagerCompat.notify(NotificationsActivity.NOTIFICATION_ID, notification);
}
}