Пример #1
0
        private void SendNotification(string monitorMessageDescription = "", ApiModels.Message message = null)
        {
            var id = _identityRandomizer.Next();

            var notification = new NotificationCompat.Builder(this)

                               .SetSmallIcon(Resource.Mipmap.icon)
                               .SetContentIntent(this.BuildIntentToShowMainActivity(id, message))
                               .SetContentTitle(monitorMessageDescription)
                               .SetAutoCancel(true)
                               .SetContentText(PollingServiceConstants.TapForMoreDetails)
                               .SetOnlyAlertOnce(false);

            if (SettingsProvider.IsDndModeEnabled)
            {
                notification.SetPriority((int)NotificationPriority.Low);
            }

            var notificationManager = this.GetSystemService(NotificationService) as NotificationManager;

            var notificationChannel = this.CreateNotificationChannelIfNecessary();

            if (notificationChannel != null)
            {
                notification.SetChannelId(notificationChannel.Id);
                notificationManager.CreateNotificationChannel(notificationChannel);
            }

            notificationManager.Notify(_identityRandomizer.Next(), notification.Build());

            this.RunVisualEffects();
        }
Пример #2
0
        private void NotifyUi(ApiModels.Message message = null)
        {
            var uiNotificationIntent = new Intent(BroadcastingConstants.UiNotification);

            if (message != null)
            {
                var serializedModel = JsonConvert.SerializeObject(message);

                uiNotificationIntent.PutExtra(BroadcastingConstants.UiNotificationKey, serializedModel);
            }

            SendBroadcast(uiNotificationIntent);
        }
Пример #3
0
        private PendingIntent BuildIntentToShowMainActivity(int id = -1, ApiModels.Message message = null)
        {
            var notificationIntent = new Intent(this, typeof(MainActivity));

            notificationIntent.SetFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTask);

            if (message != null)
            {
                var serializedMessage = JsonConvert.SerializeObject(message);
                notificationIntent.PutExtra(MainActivityConstants.SerializedMessageModelExtraKey, serializedMessage);
            }

            var pendingIntent = PendingIntent.GetActivity(this, id, notificationIntent, PendingIntentFlags.UpdateCurrent);

            return(pendingIntent);
        }