private void OnButtonClick() { requestCode++; // Build PendingIntent var pendingIntent = MakePendingIntent(); var replyText = GetString(Resource.String.reply_text); // Create remote input that will read text var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(KEY_TEXT_REPLY) .SetLabel(replyText) .Build(); // Build action for noticiation var action = new NotificationCompat.Action.Builder(Resource.Drawable.action_reply, replyText, pendingIntent) .AddRemoteInput(remoteInput) .Build(); // Build notification var notification = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.reply) .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.avatar)) .SetContentText("Hey, it is James! What's up?") .SetContentTitle(GetString(Resource.String.message)) .SetAutoCancel(true) .AddAction(action) .Build(); // Notify using (var notificationManager = NotificationManagerCompat.From(this)) { notificationManager.Notify(requestCode, notification); } }
private void OnButtonClick() { requestCode++; // Build PendingIntent var pendingIntent = MakePendingIntent(); var replyText = GetString(Resource.String.reply_text); // Create remote input that will read text var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(KEY_TEXT_REPLY) .SetLabel(replyText) .Build(); // Build action for noticiation var action = new NotificationCompat.Action.Builder(Resource.Drawable.action_reply, replyText, pendingIntent) .AddRemoteInput(remoteInput) .Build(); // Build notification var notification = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.reply) .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.avatar)) .SetContentText("Hey, it is James! What's up?") .SetContentTitle(GetString(Resource.String.message)) .SetAutoCancel(true) .AddAction(action) .Build(); // Notify using (var notificationManager = NotificationManagerCompat.From(this)) { notificationManager.Notify(requestCode, notification); } }
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()); }
private void btnSendNotificationWithVoiceInput_OnClick(object sender, EventArgs eventArgs) { // Key for the string that's delivered in the action's intent var replyChoices = new string[] { "Choice 1", "Choice 2" }; var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(EXTRA_VOICE_REPLY) .SetLabel("Reply") .SetChoices(replyChoices) .Build(); // Build intent for notification content var pendingIntent = new Intent(Context, typeof(AndroidWearStep1ActivityExtraIntent)); pendingIntent.PutExtra("EXTRA_EVENT_ID", 2); var viewPendingIntent = PendingIntent.GetActivity(Context, 0, pendingIntent, PendingIntentFlags.UpdateCurrent); // Create the reply action and add the remote input var action = new NotificationCompat.Action.Builder(Resource.Drawable.ic_media_play, "Reply!", viewPendingIntent) .AddRemoteInput(remoteInput) .Build(); // Build the notification and add the action via WearableExtender var notification = new NotificationCompat.Builder(Context) .SetSmallIcon(Resource.Drawable.icon9) .SetContentTitle("Notification") .SetContentText("With Voice Input Action") .Extend(new NotificationCompat.WearableExtender().AddAction(action)) .Build(); NotificationManagerCompat.From(Context).Notify(118, notification); }
private NotificationCompat.Action GetAction(NotificationCompat.Builder builder, Intent notificationIntent, Action actualAction) { var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(KEY_TEXT_REPLY).SetLabel("Akcja 1").Build(); var pendingIntent = PendingIntent.GetBroadcast(this.ctx, 0, notificationIntent, PendingIntentFlags.UpdateCurrent); return(new NotificationCompat.Action.Builder(Resource.Drawable.Icon, "Akcja 1", pendingIntent).AddRemoteInput(remoteInput).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()); }
void SendNotification(string messageHead, string messageBody, IDictionary <string, string> data) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); foreach (var key in data.Keys) { intent.PutExtra(key, data[key]); } //알림 내역 intent var pendingIntent = PendingIntent.GetActivity(this, MainActivity.NOTIFICATION_ID, intent, PendingIntentFlags.OneShot); PendingIntent helpPendingIntent = PendingIntent.GetBroadcast( this, REQUEST_CODE_HELP, new Intent(this, typeof(NotificationReceiver)) .PutExtra(KEY_INTENT_HELP, REQUEST_CODE_HELP), PendingIntentFlags.OneShot ); Android.Support.V4.App.RemoteInput remoteInput = new Android.Support.V4.App.RemoteInput.Builder(NOTIFICATION_REPLY) .SetLabel("Please enter your name") .Build(); //NotificationCompat.Action action = // new NotificationCompat.Action.Builder(Resource.Drawable.abc_edit_text_material, // "Reply Now...", helpPendingIntent) // .AddRemoteInput(remoteInput) // .Build(); var notificationBuilder = new NotificationCompat.Builder(this, MainActivity.CHANNEL_ID) .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification) .SetContentTitle(messageHead) .SetContentText(messageBody) .SetAutoCancel(true) .SetColor(Color.HoloRedDark) .SetVibrate(new long[] { 100, 200, 300, 400, 500, 400, 300, 200, 400 }) .SetContentIntent(pendingIntent) .AddAction(Resource.Drawable.abc_edit_text_material, GetString(Resource.String.finish), helpPendingIntent) .AddAction(Resource.Drawable.abc_edit_text_material, GetString(Resource.String.ok), pendingIntent); var notificationManager = NotificationManagerCompat.From(this); int not_nu = generateRandom(); //notificationManager.Notify(MainActivity.NOTIFICATION_ID, notificationBuilder.Build()); notificationManager.Notify(not_nu, notificationBuilder.Build()); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); Button button = FindViewById <Button>(Resource.Id.MyButton); button.Click += delegate { // Wear の入力画面を構築 // RemoteInput.Builder だと Android.RemoteInput と競合するのでフルで指定しています。 // 正式な書き方は不明です。。 var remoteInput = new Android.Support.V4.App.RemoteInput.Builder("Reply") .SetLabel(GetText(Resource.String.Reply)) // "Reply Label" .Build(); // pendingIntent で起動する Activity var intent = new Intent(this, typeof(StartActionActivity)); // Wear の Update を待つ処理 var replyPendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent); // Wear でスワイプ (Extender?) した際のアクション var replyAction = new NotificationCompat.Action.Builder( Android.Resource.Drawable.IcButtonSpeakNow, GetText(Resource.String.Reply), replyPendingIntent) // "リプライ" .AddRemoteInput(remoteInput) .Build(); // Wear の Extender を構築 var wealableExtender = new NotificationCompat.WearableExtender() .AddAction(replyAction); // Wear の Notification を構築 var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Android.Resource.Drawable.IcDialogAlert) .SetContentTitle(GetText(Resource.String.AlertTitle)) // "アラート" .SetContentText(GetText(Resource.String.AlertMessage)) // "左にスワイプしてください" .Extend(wealableExtender); // Notification を送る Activity を指定 var notificationManager = NotificationManagerCompat.From(this); // 実際に Notification を送る notificationManager.Notify(1, notificationBuilder.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 ()); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var intent = new Intent(this, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(this); var title = "I <3 C#"; var message = "Seattle Code Camp rocks!"; var messageLong = "Seattle Code Camp is awesome, I can't wait to see the Xamarin.Forms Demo later! From what I hear it is going to be the best thing ever!"; //Standard Notification FindViewById <Button>(Resource.Id.notification).Click += (sender, e) => { var style = new NotificationCompat.BigTextStyle(); style.BigText(messageLong); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true); var notification = builder.Build(); manager.Notify(0, notification); }; //Standard action with action FindViewById <Button>(Resource.Id.notification_action).Click += (sender, e) => { NotificationCompat.Action reply = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply, "Reply", contentIntent) .Build(); var style = new NotificationCompat.BigTextStyle(); style.BigText(messageLong); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .AddAction(reply); var notification = builder.Build(); manager.Notify(0, notification); }; //Special Button for Wear FindViewById <Button>(Resource.Id.notification_wear_action).Click += (sender, e) => { NotificationCompat.Action favorite = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_rating_favorite, "Favorite", contentIntent) .Build(); NotificationCompat.Action reply = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply, "Reply", contentIntent) .Build(); var style = new NotificationCompat.BigTextStyle(); style.BigText(messageLong); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .AddAction(reply) .Extend(new NotificationCompat.WearableExtender().AddActions(new [] { reply, favorite })); var notification = builder.Build(); manager.Notify(0, notification); }; //Custom Background FindViewById <Button>(Resource.Id.notification_wear_background).Click += (sender, e) => { var action = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_rating_favorite, "Favorite", contentIntent) .Build(); var wearableExtender = new NotificationCompat.WearableExtender() .SetHintHideIcon(true) .SetBackground(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_background)) .AddAction(action) ; var style = new NotificationCompat.BigTextStyle(); style.BigText(messageLong); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .AddAction(Resource.Drawable.ic_stat_social_reply, "Reply", contentIntent) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }; //Pages FindViewById <Button>(Resource.Id.notification_wear_pages).Click += (sender, e) => { // Create builder for the main notification var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle("Page 1") .SetContentText("Short message") .SetContentIntent(contentIntent); // Create a big text style for the second page var secondPageStyle = new NotificationCompat.BigTextStyle(); secondPageStyle.SetBigContentTitle("Page 2") .BigText(messageLong); // Create second page notification var secondPageNotification = new NotificationCompat.Builder(this) .SetStyle(secondPageStyle) .Build(); // Add second page with wearable extender and extend the main notification var twoPageNotification = new NotificationCompat.WearableExtender() .AddPage(secondPageNotification) .Extend(notificationBuilder) .Build(); // Issue the notification manager.Notify(0, twoPageNotification); }; //Stacked Notifications FindViewById <Button>(Resource.Id.notification_wear_stacked).Click += (sender, e) => { var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_background)); // Build the notification, setting the group appropriately var notificaiton1 = new NotificationCompat.Builder(this) .SetContentTitle("New mail from James") .SetContentText(message) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetGroup("group_1") .Extend(wearableExtender) .Build(); var notification2 = new NotificationCompat.Builder(this) .SetContentTitle("New mail from ChrisNTR") .SetContentText("this is subject #1") .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetGroup("group_1") .Extend(wearableExtender) .Build(); manager.Notify(0, notificaiton1); manager.Notify(1, notification2); }; //Voice Input FindViewById <Button>(Resource.Id.notification_wear_voice).Click += (sender, e) => { var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(ExtraVoiceReply) .SetLabel("Reply") .SetChoices(new [] { "Yes", "No", "OK you win" }) .Build(); NotificationCompat.Action reply = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply, "Reply", contentIntent) .AddRemoteInput(remoteInput) .Build(); var wearableExtender = new NotificationCompat.WearableExtender(); wearableExtender.AddAction(reply); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .AddAction(reply) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }; var voiceReply = GetMessageText(Intent); if (!string.IsNullOrWhiteSpace(voiceReply)) { FindViewById <TextView> (Resource.Id.textView1).Text = voiceReply; } }