public static void ShowNotification(Context context) { Android.Util.Log.Info("Xamarin", "Sending Notifiation to android auto"); PendingIntent readPendingIntent = PendingIntent.GetBroadcast(context, 123, GetMessageReadIntent(123), PendingIntentFlags.UpdateCurrent); Android.Support.V4.App.RemoteInput remoteInput = new Android.Support.V4.App.RemoteInput.Builder("extra voice reply") .SetLabel("Car Notification") .Build(); PendingIntent replyPendingIntent = PendingIntent.GetBroadcast(context, 123, GetMessageReplyIntent(123), PendingIntentFlags.UpdateCurrent); NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder("Hello android Auto") .SetLatestTimestamp(JavaSystem.CurrentTimeMillis()) .SetReadPendingIntent(readPendingIntent) .SetReplyAction(replyPendingIntent, remoteInput); unreadConversationBuilder.AddMessage("This is the body for android auto"); var builder = new NotificationCompat.Builder(context, "MyChannel") .SetAutoCancel(true) .SetContentTitle("Hello Android Auto") .SetSmallIcon(Resource.Drawable.abc_ic_menu_share_mtrl_alpha) .SetContentText($"this is the body") .Extend(new NotificationCompat.CarExtender() .SetUnreadConversation(unreadConversationBuilder.Build())); var notificationManager = NotificationManagerCompat.From(context); notificationManager.Notify(123456, builder.Build()); }
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()); }
public static void ShowNotification(Context context) { Android.Util.Log.Info("Xamarin", "Sending notification to Android & Android Auto!"); PendingIntent readPendingIntent = PendingIntent.GetBroadcast(context, 123, GetMessageReadIntent(123), PendingIntentFlags.UpdateCurrent); Android.Support.V4.App.RemoteInput remoteInput = new Android.Support.V4.App.RemoteInput.Builder("extra_voice_reply") .SetLabel("carnotification") .Build(); PendingIntent replyIntent = PendingIntent.GetBroadcast(context, 123, GetMessageReplyIntent(123), PendingIntentFlags.UpdateCurrent); NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder("Hello Android Auto From Xamarin") .SetLatestTimestamp(JavaSystem.CurrentTimeMillis()) .SetReadPendingIntent(readPendingIntent) .SetReplyAction(replyIntent, remoteInput); unreadConversationBuilder.AddMessage("This is the body for android auto."); var builder = new NotificationCompat.Builder(context, "MyChannel") .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentTitle("Hello Android From Xamarin") // Set the title .SetSmallIcon(Resource.Drawable.design_ic_visibility) .SetContentText($"This is the body for android device.") .Extend(new NotificationCompat.CarExtender() .SetUnreadConversation( unreadConversationBuilder.Build() ) ); // Finally, publish the notification: var notificationManager = NotificationManagerCompat.From(context); notificationManager.Notify(123456, builder.Build()); }
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 ()); }