public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);

            RemoteMessage.Notification nfc = message.GetNotification();

            if (nfc != null)
            {
                EbNFData nf = new EbNFData {
                    Message = nfc.Body
                };
                this.SendLocalNotification(nf);
            }
            else
            {
                try
                {
                    if (message.Data?.Count > 0)
                    {
                        EbNFData nfData = new EbNFData(message.Data);
                        this.SendLocalNotification(nfData);
                    }
                }
                catch (Exception ex)
                {
                    EbLog.Error("error on deserializing EbNFData");
                    EbLog.Error(ex.Message);
                }
            }
        }
Beispiel #2
0
        /**
         * This method is used to receive downstream data messages.
         * This method callback must be completed in 10 seconds. Otherwise, you need to start a new Job for callback processing.
         *
         * @param message RemoteMessage
         */
        public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Info(TAG, "onMessageReceived is called");
            if (message == null)
            {
                Log.Error(TAG, "Received message entity is null!");
                return;
            }

            Log.Info(TAG, "getCollapseKey: " + message.CollapseKey
                     + "\n getData: " + message.Data
                     + "\n getFrom: " + message.From
                     + "\n getTo: " + message.To
                     + "\n getMessageId: " + message.MessageId
                     + "\n getOriginalUrgency: " + message.OriginalUrgency
                     + "\n getUrgency: " + message.Urgency
                     + "\n getSendTime: " + message.SentTime
                     + "\n getMessageType: " + message.MessageType
                     + "\n getTtl: " + message.Ttl);

            RemoteMessage.Notification notification = message.GetNotification();
            if (notification != null)
            {
                Log.Info(TAG, "\n getImageUrl: " + notification.ImageUrl
                         + "\n getTitle: " + notification.Title
                         + "\n getTitleLocalizationKey: " + notification.TitleLocalizationKey
                         + "\n getBody: " + notification.Body
                         + "\n getBodyLocalizationKey: " + notification.BodyLocalizationKey
                         + "\n getIcon: " + notification.Icon
                         + "\n getSound: " + notification.Sound
                         + "\n getTag: " + notification.Tag
                         + "\n getColor: " + notification.Color
                         + "\n getClickAction: " + notification.ClickAction
                         + "\n getChannelId: " + notification.ChannelId
                         + "\n getLink: " + notification.Link
                         + "\n getNotifyId: " + notification.NotifyId);
            }

            Intent intent = new Intent();

            intent.SetAction(PUSHDEMO_ACTION);
            intent.PutExtra("method", "onMessageReceived");
            intent.PutExtra("msg", "onMessageReceived called, message id:" + message.MessageId + ", payload data:"
                            + message.Data);

            SendBroadcast(intent);

            bool judgeWhetherIn10s = false;

            // If the messages are not processed in 10 seconds, the app needs to use WorkManager for processing.
            if (judgeWhetherIn10s)
            {
                StartWorkManagerJob(message);
            }
            else
            {
                // Process message within 10s
                ProcessWithin10s(message);
            }
        }
        void SendNotification(RemoteMessage.Notification notification, IDictionary <string, string> data)
        {
            Log.Debug(TAG, $"SendNotification");
            try
            {
                var intent = new Intent(this, typeof(MainActivity));
                intent.AddFlags(ActivityFlags.ClearTop);
                data.Select(item => intent.PutExtra(item.Key, item.Value));

                var notificationBuilder = new Notification.Builder(this, CHANNEL_ID)
                                          .SetSmallIcon(Resource.Drawable.abc_ic_ab_back_material)
                                          .SetContentTitle(notification.Title)
                                          .SetContentText(notification.Body)
                                          .SetAutoCancel(true)
                                          .SetContentIntent(PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot));

                var notificationManager = NotificationManager.FromContext(this);

                if ((notificationManager != null) && (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O))
                {
                    var channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationImportance.Default);
                    notificationManager.CreateNotificationChannel(channel);
                    Log.Debug(TAG, $"Push notification channel {CHANNEL_ID} created");
                }

                notificationManager.Notify(0, notificationBuilder.Build());
            }
            catch (Exception ex)
            {
                Log.Error(TAG, $"SendNotification: {ex.Message}");
            }
        }
        private void SendNotification(RemoteMessage.Notification messageBody)
        {
            var importance           = NotificationImportance.High;
            NotificationChannel chan = new NotificationChannel(URGENT_CHANNEL, "Urgent", importance);

            chan.EnableVibration(true);
            chan.LockscreenVisibility = NotificationVisibility.Public;

            // Choose the activity you want to push
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);

            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.ic_home_black_24dp)
                                      .SetContentTitle(messageBody.Title)
                                      .SetContentText(messageBody.Body)
                                      .SetContentIntent(pendingIntent)
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                      .SetAutoCancel(true)
                                      .SetChannelId(URGENT_CHANNEL);

            NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.CreateNotificationChannel(chan);

            notificationManager.Notify(NOTIFY_ID, notificationBuilder.Build());
        }
        public static Dictionary <string, string> FromMap(this RemoteMessage message)
        {
            if (message == null)
            {
                return(null);
            }
            Dictionary <string, string> result = new Dictionary <string, string>();

            result[RemoteMessageAttributes.CollapseKey]     = message.CollapseKey;
            result[RemoteMessageAttributes.Data]            = message.Data;
            result[RemoteMessageAttributes.DataOfMap]       = CoreUtils.DictionaryToString(message.DataOfMap);
            result[RemoteMessageAttributes.MessageId]       = message.MessageId;
            result[RemoteMessageAttributes.MessageType]     = message.MessageType;
            result[RemoteMessageAttributes.OriginalUrgency] = message.OriginalUrgency.ToString();
            result[RemoteMessageAttributes.Urgency]         = message.Urgency.ToString();
            result[RemoteMessageAttributes.Ttl]             = message.Ttl.ToString();
            result[RemoteMessageAttributes.SentTime]        = message.SentTime.ToString();
            result[RemoteMessageAttributes.To]          = message.To;
            result[RemoteMessageAttributes.From]        = message.From;
            result[RemoteMessageAttributes.Token]       = message.Token;
            result[RemoteMessageAttributes.ReceiptMode] = message.ReceiptMode.ToString();
            result[RemoteMessageAttributes.SendMode]    = message.SendMode.ToString();
            result[RemoteMessageAttributes.Contents]    = message.DescribeContents().ToString();

            if (message.GetNotification() != null)
            {
                RemoteMessage.Notification notification = message.GetNotification();

                result[RemoteMessageAttributes.Title] = notification.Title;
                result[RemoteMessageAttributes.TitleLocalizationKey]  = notification.TitleLocalizationKey;
                result[RemoteMessageAttributes.TitleLocalizationArgs] = notification.GetTitleLocalizationArgs().CheckNString();
                result[RemoteMessageAttributes.BodyLocalizationKey]   = notification.BodyLocalizationKey;
                result[RemoteMessageAttributes.BodyLocalizationArgs]  = notification.GetBodyLocalizationArgs().CheckNString();
                result[RemoteMessageAttributes.Body]             = notification.Body;
                result[RemoteMessageAttributes.Icon]             = notification.Icon;
                result[RemoteMessageAttributes.Sound]            = notification.Sound;
                result[RemoteMessageAttributes.Tag]              = notification.Tag;
                result[RemoteMessageAttributes.Color]            = notification.Color;
                result[RemoteMessageAttributes.ClickAction]      = notification.ClickAction;
                result[RemoteMessageAttributes.ChannelId]        = notification.ChannelId;
                result[RemoteMessageAttributes.ImageUrl]         = notification.ImageUrl + "";
                result[RemoteMessageAttributes.Link]             = notification.Link + "";
                result[RemoteMessageAttributes.NotifyId]         = notification.NotifyId + "";
                result[RemoteMessageAttributes.When]             = notification.When + "";
                result[RemoteMessageAttributes.LightSettings]    = notification.GetLightSettings().CheckNString();
                result[RemoteMessageAttributes.BadgeNumber]      = notification.BadgeNumber + "";
                result[RemoteMessageAttributes.Importance]       = notification.Importance + "";
                result[RemoteMessageAttributes.Ticker]           = notification.Ticker;
                result[RemoteMessageAttributes.VibrateConfig]    = notification.GetVibrateConfig().CheckNString();
                result[RemoteMessageAttributes.Visibility]       = notification.Visibility + "";
                result[RemoteMessageAttributes.IntentUri]        = notification.IntentUri;
                result[RemoteMessageAttributes.IsAutoCancel]     = notification.IsAutoCancel + "";
                result[RemoteMessageAttributes.IsLocalOnly]      = notification.IsLocalOnly + "";
                result[RemoteMessageAttributes.IsDefaultLight]   = notification.IsDefaultLight + "";
                result[RemoteMessageAttributes.IsDefaultSound]   = notification.IsDefaultSound + "";
                result[RemoteMessageAttributes.IsDefaultVibrate] = notification.IsDefaultVibrate + "";
            }

            return(result);
        }
Beispiel #6
0
        private void ShowAlert(RemoteMessage.Notification notification)
        {
            Looper.Prepare();
            AlertDialog.Builder builder = new AlertDialog.Builder(Forms.Context);
            builder.SetTitle(notification.Title);
            builder.SetMessage(notification.Body);
            builder.SetNegativeButton("Ok", (s, a) => { });

            AlertDialog alert = builder.Create();

            alert.Show();
            Looper.Loop();
        }
Beispiel #7
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            RemoteMessage.Notification notification = message.GetNotification();

            // На случай, если сообщение содержит только данные (data message).
            if (notification == null)
            {
                return;
            }

            String title     = notification.Title;
            String text      = notification.Body;
            String channelId = notification.ChannelId;

            NotificationUtilities.DisplayNotification(this, channelId, 0, title, text, message.Data);
        }
Beispiel #8
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Info(TAG, "onMessageReceived is called");
            if (message == null)
            {
                Log.Error(TAG, "Received message entity is null!");
                return;
            }

            Log.Info(TAG, "getCollapseKey: " + message.CollapseKey
                     + "\n getData: " + message.Data
                     + "\n getFrom: " + message.From
                     + "\n getTo: " + message.To
                     + "\n getMessageId: " + message.MessageId
                     + "\n getOriginalUrgency: " + message.OriginalUrgency
                     + "\n getUrgency: " + message.Urgency
                     + "\n getSendTime: " + message.SentTime
                     + "\n getMessageType: " + message.MessageType
                     + "\n getTtl: " + message.Ttl);

            RemoteMessage.Notification notification = message.GetNotification();
            if (notification != null)
            {
                Log.Info(TAG, "\n getImageUrl: " + notification.ImageUrl
                         + "\n getTitle: " + notification.Title
                         + "\n getTitleLocalizationKey: " + notification.TitleLocalizationKey
                         + "\n getBody: " + notification.Body
                         + "\n getBodyLocalizationKey: " + notification.BodyLocalizationKey
                         + "\n getIcon: " + notification.Icon
                         + "\n getSound: " + notification.Sound
                         + "\n getTag: " + notification.Tag
                         + "\n getColor: " + notification.Color
                         + "\n getClickAction: " + notification.ClickAction
                         + "\n getChannelId: " + notification.ChannelId
                         + "\n getLink: " + notification.Link
                         + "\n getNotifyId: " + notification.NotifyId);
            }

            if (message.DataOfMap.ContainsKey("DATA_STATE"))
            {
                Log.Info(TAG, "DATA_STATE Exist");
                ISharedPreferences       sharedPreferences = this.GetSharedPreferences("Remote_Config", FileCreationMode.Private);
                ISharedPreferencesEditor editor            = sharedPreferences.Edit();
                editor.PutBoolean("DATA_OLD", true).Apply();
                Toast.MakeText(this, "The Configuration will be refreshed", ToastLength.Short).Show();
            }
        }
 void SendNotification(RemoteMessage.Notification message, IDictionary <string, string> data)
 {
     using (var intent = new Intent(this, typeof(MainActivity)))
     {
         intent.AddFlags(ActivityFlags.ClearTop);
         if (data != null)
         {
             foreach (var key in data.Keys)
             {
                 intent.PutExtra(key, data[key]);
             }
         }
     }
     Device.BeginInvokeOnMainThread(() =>
     {
         AppService.ShowAlert(message.Title, message.Body);
     });
 }
Beispiel #10
0
        protected virtual string?ParseNotificationTitleFromData(
            RemoteMessage.Notification pushMessage,
            IDictionary <string, string> pushNotificationData)
        {
            if (pushMessage == null)
            {
                return(GetStringFromDictionary(pushNotificationData, DataTitleKey));
            }
            else
            {
                string?title = null;
                if (!string.IsNullOrEmpty(pushMessage.TitleLocalizationKey))
                {
                    title = GetResourceString(pushMessage.TitleLocalizationKey, pushMessage.GetTitleLocalizationArgs());
                }

                return(title ?? pushMessage.Title);
            }
        }
Beispiel #11
0
        protected virtual string?ParseNotificationMessageFromData(
            RemoteMessage.Notification pushMessage,
            IDictionary <string, string> pushNotificationData)
        {
            if (pushMessage == null)
            {
                return(GetStringFromDictionary(pushNotificationData, DataBodyKey));
            }
            else
            {
                string?body = null;
                if (!string.IsNullOrEmpty(pushMessage.BodyLocalizationKey))
                {
                    body = GetResourceString(pushMessage.BodyLocalizationKey, pushMessage.GetBodyLocalizationArgs());
                }

                return(body ?? pushMessage.Body);
            }
        }
 public override void OnMessageReceived(RemoteMessage message)
 {
     // TODO(developer): Handle FCM messages here.
     // If the application is in the foreground handle both data and notification messages here.
     // Also if you intend on generating your own notifications as a result of a received FCM
     // message, here is where that should be initiated. See sendNotification method below.
     System.Diagnostics.Debug.WriteLine(TAG, "From: " + message.From);
     RemoteMessage.Notification tmp = message.GetNotification();
     if (tmp != null)
     {
         System.Diagnostics.Debug.WriteLine(TAG, "Notification Message Body: " + message.GetNotification().Body);
         var body = message.GetNotification().Body;
         ScheduleNotification(body, message.Data);
     }
     else
     {
         ScheduleNotification("123", message.Data);
     }
 }
        private void SendNotification(RemoteMessage.Notification message)//metodo de generacion de la notificacion de forma local
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var defaultSoundUri     = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.logoOtb)
                                      .SetContentTitle(message.Title)
                                      .SetContentText(message.Body)
                                      .SetAutoCancel(true)
                                      .SetSound(defaultSoundUri)
                                      .SetContentIntent(pendingIntent);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
Beispiel #14
0
        private void SendNotification(RemoteMessage.Notification notification, IDictionary <string, string> data)
        {
            var intent = new Intent(notification.ClickAction);

            intent.AddFlags(ActivityFlags.ClearTop);
            foreach (string key in data.Keys)
            {
                intent.PutExtra(key, data[key]);
            }
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var notificationBuilder = new Notification.Builder(this)
                                      .SetSmallIcon((int)typeof(Resource.Drawable)
                                                    .GetField(notification.Icon).GetValue(null))
                                      .SetContentTitle(notification.Title)
                                      .SetContentText(notification.Body)
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                      .SetAutoCancel(true)
                                      .SetContentIntent(pendingIntent);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
Beispiel #15
0
 internal void ReceiveMessage(RemoteMessage.Notification notification)
 {
     MessageReceived?.Invoke(this, EventArgs.Empty);
 }
Beispiel #16
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            RemoteMessage.Notification notification = message.GetNotification();

            ShowAlert(notification);
        }