public MessageView(LazuriteNotification notification) { InitializeComponent(); lblText.Text = notification.Message.Text.Trim(); lblDateTime.Text = notification.Message.DateTime.ToString(); lblTitle.Text = notification.Message.Header.Trim(); lblNew.IsVisible = !notification.IsRead; }
public void Notify(Lazurite.Shared.Message message) { var newId = GetNextNotificationId(); var lazNotification = new LazuriteNotification(); lazNotification.Id = newId; lazNotification.Message = message; _notificationsCache.Insert(0, lazNotification); var context = global::Android.App.Application.Context; var activityIntent = new Intent(context, typeof(MainActivity)); activityIntent.PutExtra(Keys.NeedOpenNotifications, newId); var showActivityIntent = PendingIntent.GetActivity(Application.Context, 0, activityIntent, PendingIntentFlags.UpdateCurrent); var notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager; var channelId = Build.VERSION.SdkInt >= BuildVersionCodes.O ? CreateNotificationChannel(notificationManager) : string.Empty; var notificationBuilder = new NotificationCompat.Builder(context, channelId); notificationBuilder.SetContentTitle(message.Header); notificationBuilder.SetContentText(message.Text); notificationBuilder.SetContentIntent(showActivityIntent); notificationBuilder.SetSmallIcon(Resource.Drawable.message); notificationBuilder.SetLargeIcon(BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.icon)); notificationBuilder.SetPriority((int)NotificationPriority.Max); notificationBuilder.SetDefaults((int)NotificationDefaults.All); notificationBuilder.SetColor(Color.Purple); notificationBuilder.SetOnlyAlertOnce(true); notificationBuilder.SetAutoCancel(true); notificationBuilder.SetCategory(Notification.CategoryMessage); notificationBuilder.SetVisibility((int)NotificationVisibility.Private); notificationManager.Notify(newId, notificationBuilder.Build()); if (Singleton.Any <INotificationsHandler>()) { var notificationHandler = Singleton.Resolve <INotificationsHandler>(); if (notificationHandler.NeedViewPermanently) { notificationHandler.UpdateNotificationsInfo(); } } }
public void Notify(Lazurite.Shared.Message message) { var newId = GetNextNotificationId(); var lazNotification = new LazuriteNotification(); lazNotification.Id = newId; lazNotification.Message = message; _notificationsCache.Insert(0, lazNotification); var context = global::Android.App.Application.Context; var notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager; Notification.Builder builder; if (Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.O) { var channelId = "channel1"; NotificationChannel mChannel; mChannel = new NotificationChannel(channelId, "laz", NotificationImportance.High); mChannel.EnableLights(true); mChannel.LightColor = Color.White; mChannel.SetShowBadge(true); mChannel.LockscreenVisibility = NotificationVisibility.Private; notificationManager.CreateNotificationChannel(mChannel); builder = new Notification.Builder(context, channelId); } else { builder = new Notification.Builder(context); } builder.SetContentTitle(message.Header); builder.SetContentText(message.Text); builder.SetSmallIcon(Resource.Drawable.icon); builder.SetVisibility(NotificationVisibility.Private); builder.SetOnlyAlertOnce(true); builder.SetDefaults(NotificationDefaults.All); builder.SetAutoCancel(true); builder.SetColor(Color.Argb(0, 255, 255, 255).ToArgb()); var activityIntent = new Intent(context, typeof(MainActivity)); activityIntent.PutExtra(Keys.NeedOpenNotifications, newId); var showActivityIntent = PendingIntent.GetActivity(Application.Context, 0, activityIntent, PendingIntentFlags.UpdateCurrent); builder.SetContentIntent(showActivityIntent); var notification = builder.Build(); notificationManager.Notify(newId, notification); if (Singleton.Any <INotificationsHandler>()) { var notificationHandler = Singleton.Resolve <INotificationsHandler>(); if (notificationHandler.NeedViewPermanently) { notificationHandler.UpdateNotificationsInfo(); } } }