void SendNotification(int howManyConversations, int messagesPerConversation) { Conversations.Conversation[] conversations = Conversations.GetUnreadConversations( howManyConversations, messagesPerConversation); foreach (Conversations.Conversation conv in conversations) { SendNotificationForConversation(conv); } }
void SendNotificationForConversation (Conversations.Conversation conversation) { // A pending Intent for reads PendingIntent readPendingIntent = PendingIntent.GetBroadcast (ApplicationContext, conversation.ConversationId, GetMessageReadIntent (conversation.ConversationId), PendingIntentFlags.UpdateCurrent); // Build a RemoteInput for receiving voice input in a Car Notification var remoteInput = new Android.Support.V4.App.RemoteInput.Builder (EXTRA_VOICE_REPLY) .SetLabel (ApplicationContext.GetString (Resource.String.notification_reply)) .Build (); // Building a Pending Intent for the reply action to trigger PendingIntent replyIntent = PendingIntent.GetBroadcast (ApplicationContext, conversation.ConversationId, GetMessageReplyIntent (conversation.ConversationId), PendingIntentFlags.UpdateCurrent); // Create the UnreadConversation and populate it with the participant name, // read and reply intents. var unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder (conversation.ParticipantName) .SetLatestTimestamp (conversation.Timestamp) .SetReadPendingIntent (readPendingIntent) .SetReplyAction (replyIntent, remoteInput); // Note: Add messages from oldest to newest to the UnreadConversation.Builder StringBuilder messageForNotification = new StringBuilder (); for (int i = 0; i < conversation.Messages.Count; i++) { unreadConvBuilder.AddMessage (conversation.Messages [i]); messageForNotification.Append (conversation.Messages [i]); if (i != conversation.Messages.Count - 1) messageForNotification.Append (EOL); } NotificationCompat.Builder builder = new NotificationCompat.Builder (ApplicationContext) .SetSmallIcon (Resource.Drawable.notification_icon) .SetLargeIcon (BitmapFactory.DecodeResource ( ApplicationContext.Resources, Resource.Drawable.android_contact)) .SetContentText (messageForNotification.ToString ()) .SetWhen (conversation.Timestamp) .SetContentTitle (conversation.ParticipantName) .SetContentIntent (readPendingIntent) .Extend (new NotificationCompat.CarExtender () .SetUnreadConversation (unreadConvBuilder.Build ()) .SetColor (ApplicationContext .Resources.GetColor (Resource.Color.default_color_light))); MessageLogger.LogMessage (ApplicationContext, "Sending notification " + conversation.ConversationId + " conversation: " + conversation); mNotificationManager.Notify (conversation.ConversationId, builder.Build ()); }