public override void OnMessageReceived(RemoteMessage message)
        {
            //message.Data.TryGetValue("idUr", out var idUr);
            var msg = message.GetNotification();

            CreateNotification(ApplicationContext, msg?.Title, msg?.Body);
        }
示例#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);
            }
        }
示例#3
0
        /**
         * Called when message is received.
         */
        public override void OnMessageReceived(RemoteMessage remoteMessage)
        {
            // There are two types of messages data messages and notification messages. Data messages are handled
            // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
            // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
            // is in the foreground. When the app is in the background an automatically generated notification is displayed.
            // When the user taps on the notification they are returned to the app. Messages containing both notification
            // and data payloads are treated as notification messages. The Firebase console always sends notification
            // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options

            string remoteCommandId = string.Empty;
            IDictionary <string, string> commandParams = null;

            Debug.WriteLine("From: " + remoteMessage.From, TAG);

            if (remoteMessage.GetNotification() != null)
            {
                Debug.WriteLine("Notification Message Body: " + remoteMessage.GetNotification().Body, TAG);
                remoteCommandId = remoteMessage.GetNotification().Body;
            }
            else if (remoteMessage.Data != null)
            {
                Debug.WriteLine("Data Message received. Dictionary {" + string.Join(";", remoteMessage.Data) + "}", TAG);
                if (remoteMessage.Data.ContainsKey("CommandId"))
                {
                    remoteCommandId = remoteMessage.Data["CommandId"];
                }
                commandParams = remoteMessage.Data;
            }

            Debug.WriteLine(string.Format("Executing command {0}", remoteCommandId), TAG);
            bool commandResult = true;

            if (commandParams != null && commandParams.Count > 0)
            {
                commandResult = CommandDispatcher.getInstance().ExecuteCommandWithParams(remoteCommandId, commandParams);
            }
            else
            {
                commandResult = CommandDispatcher.getInstance().ExecuteCommand(remoteCommandId);
            }

            if (commandResult)
            {
                Debug.WriteLine(string.Format("Command \"{0}\" executed successfull!", remoteCommandId));
            }
        }
        /*public Notification GenerateNotification(Intent intent)
        {
            if (intent.Extras != null)
            {
                var shipmentId = long.Parse((string)intent.Extras.Get(Constants.SHIPMENT_ID_KEY));
                var jobReference = (string)intent.Extras.Get(Constants.JOB_REFERENCE_KEY);
                var transportType = (string)intent.Extras.Get(Constants.TRANSPORT_TYPE_KEY);
                var title = (string)intent.Extras.Get("Title");
                var description = (string)intent.Extras.Get("Description");
                Shipment shipment = ((List<Shipment>)ListDataModel.shipments).Find(
                delegate (Shipment sm)
                {
                    return sm.JobReferenceNumber.ToLowerInvariant().Contains(jobReference.Trim().ToLowerInvariant());
                });
                app.Notify(true, shipment);
            }
        }*/

        private void HandleNotification(RemoteMessage message)
        {
            int id = DateTime.Now.Millisecond;
            Log.Debug(TAG, "message data: " + message.Data); // this will return android.support.v4.util.ArrayMap
            Log.Debug(TAG, "message data: " + message.Data.GetEnumerator().ToString()); //  Android.Runtime.JavaDictionary`2+<GetEnumerator>c__Iterator0[System.String,System.String]
            Log.Debug(TAG, "From: " + message.From); //From: sender
            Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
            var intent = message.ToIntent();

            if (intent.Extras != null)
            {
                foreach (var key in intent.Extras.KeySet())
                {
                    var value = intent.Extras.GetString(key);
                    Log.Debug(TAG, "Key: {0} Value: {1}", key.ToString(), Convert.ToString(value));
                }
            }

            Models.Notification notification = new Models.Notification
            {
                Title = message.GetNotification().Title,
                Description = message.GetNotification().Body,
                ReceiptDateTime = DateTime.Now,
                Payload = new Models.NotificationPayload(),
                IsRead = false
            };

            if (intent.Extras.ContainsKey(Constants.SHIPMENT_ID_KEY))
            {
                notification.Payload.ShipmentId = long.Parse(((string)intent.Extras.Get(Constants.SHIPMENT_ID_KEY)).Trim());
            }

            if (intent.Extras.ContainsKey(Constants.JOB_REFERENCE_KEY))
            {
                notification.Payload.JobReferenceNumber = ((string)intent.Extras.Get(Constants.JOB_REFERENCE_KEY)).Trim();
            }

            if (intent.Extras.ContainsKey(Constants.TRANSPORT_TYPE_KEY))
            {
                notification.Payload.TransportType = ((string)intent.Extras.Get(Constants.TRANSPORT_TYPE_KEY)).Trim();
            }

            NotificationViewModel.AddNotification(notification);
            NotificationViewModel.UpdateNotifications(Constants.Notification_VM_Instance);
            MainViewModel.UpdateBadgeAttributes(Constants.Main_VM_Instance, false, Constants.Main_VM_Instance.UnreadNotificationCount + 1);
        }
示例#5
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            //base.OnMessageReceived(message);
            //Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            var body = message.GetNotification().Body;

            SendNotification(body, message.Data);
        }
示例#6
0
        // private string TAG = "MyFirebaseMsgService";
        public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);

            SendNotification(message.GetNotification().Title, message.GetNotification().Body, message.Data);

            var powerManager = (PowerManager)GetSystemService(PowerService);
            var wakeLock     = powerManager.NewWakeLock(WakeLockFlags.ScreenDim | WakeLockFlags.AcquireCausesWakeup, "Demo");

            wakeLock.Acquire();
            wakeLock.Release();



            //IntentFilter filter = new IntentFilter(Intent.ActionScreenOn);
            //filter.AddAction(Intent.ActionScreenOn);
        }
        public override void OnMessageReceived(RemoteMessage message)
        {
            var notify = message.GetNotification();

            Log.Debug(TAG, "[Title + Content]: " + notify.Body); // Log

            SendNotificationAsync(notify, message.Data);
        }
示例#8
0
        /**
         * Called when message is received.
         */

        // [START receive_message]
        public override void OnMessageReceived(RemoteMessage message)
        {
            Android.Util.Log.Debug(TAG, "Location: OnMessageReceived*************");
            // 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.

            //Android.Util.Log.Debug(TAG, "Location: OnTokenRefresh*************");
            var refreshedToken = FirebaseInstanceId.Instance.Token;

            Android.Util.Log.Debug(TAG, "Token: " + refreshedToken);
            Android.Util.Log.Debug(TAG, "From: " + message.From);
            Android.Util.Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);

            SendNotification(message.GetNotification().Body);
        }
示例#9
0
 public override void OnMessageReceived(RemoteMessage message)
 {
     base.OnMessageReceived(message);
     try
     {
         string jsonBody = message.GetNotification().Body;
         var    item     = JsonConvert.DeserializeObject <UserMessage>(jsonBody);
         Data.Repository.SaveOrUpdate(item);
         MessagingCenter.Send("", MessageCenterKeys.NewMessageReceived, item);
         string image = message.GetNotification().Icon;
         string sound = message.GetNotification().Sound;
         SendNotificatios(item.Message, item.Title);
     }
     catch
     {
     }
 }
        public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Debug(TAG, "From: " + message.From);
            var body = message.GetNotification().Body;

            Log.Debug(TAG, "Notification Message Body: " + body);
            SendNotification(body);
        }
        public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);

            var body = message.GetNotification().Body;

            SendNotification(body, message.Data);
        }
        public override void OnMessageReceived(RemoteMessage message)
        {
            var helper         = new NotificationHelper();
            var noficationInfo = message.GetNotification();

            helper.CreateNotification(noficationInfo.Title, noficationInfo.Body);
            base.OnMessageReceived(message);
        }
示例#13
0
 public override void OnMessageReceived(RemoteMessage message)
 {
     Log.Debug(TAG, "From: " + message.From);
     Log.Debug(TAG, "To: " + message.To);
     if (message.GetNotification() != null)
     {
         //These is how most messages will be received
         Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
         // SendNotification(message.GetNotification().Body);
     }
     else
     {
         //Only used for debugging payloads sent from the Azure portal
         //SendNotification(message.Data.Values.First());
     }
     base.OnMessageReceived(message);
 }
        public override void OnMessageReceived(RemoteMessage message)
        {
            var notification = message.GetNotification();
            var title        = notification.Title;
            var body         = notification.Body;

            SendNotification(title, body);
        }
示例#15
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            IDictionary <string, string> parameters = new Dictionary <string, string>();
            var notification = message.GetNotification();

            if (notification != null)
            {
                if (!string.IsNullOrEmpty(notification.Body))
                {
                    parameters.Add("body", notification.Body);
                }

                if (!string.IsNullOrEmpty(notification.Title))
                {
                    parameters.Add("title", notification.Title);
                }

                if (!string.IsNullOrEmpty(notification.Tag))
                {
                    parameters.Add("tag", notification.Tag);
                }

                if (!string.IsNullOrEmpty(notification.Sound))
                {
                    parameters.Add("sound", notification.Sound);
                }

                if (!string.IsNullOrEmpty(notification.Icon))
                {
                    parameters.Add("icon", notification.Icon);
                }

                if (notification.Link != null)
                {
                    parameters.Add("link_path", notification.Link.Path);
                }

                if (!string.IsNullOrEmpty(notification.ClickAction))
                {
                    parameters.Add("click_action", notification.ClickAction);
                }

                if (!string.IsNullOrEmpty(notification.Color))
                {
                    parameters.Add("color", notification.Color);
                }
            }
            foreach (var d in message.Data)
            {
                if (!parameters.ContainsKey(d.Key))
                {
                    parameters.Add(d.Key, d.Value);
                }
            }

            FirebasePushNotificationManager.RegisterData(parameters);
            CrossFirebasePushNotification.Current.NotificationHandler?.OnReceived(parameters);
        }
示例#16
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);

            var body = message.GetNotification().Body;

            Log.Debug("test", "Notification Message Body: " + body);
            SendNotification(body, message.Data);
        }
        public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);
            string messageBody = string.Empty;

            if (message.GetNotification() != null)
            {
                messageBody = message.GetNotification().Body;
            }
            else
            {
                messageBody = message.Data.Values.First();
            }

            SendLocalNotification(messageBody);

            NotificationActionService.TriggerAction(messageBody);
        }
        public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);
            Log.Debug(Tag, "From: " + message.From);
            Log.Debug(Tag, "Notification Message Body: " + message.GetNotification().Body);

            // Uncomment to enable add notification while app is running
            //this.SendNotification(message.GetNotification().Title, message.GetNotification().Body);
        }
        public override void OnMessageReceived(RemoteMessage message)
        {
            var notification = message.GetNotification();

            Log.Debug(TAG, "From: " + message.From);
            Log.Debug(TAG, "Notification Message Body: " + notification.Body);

            SendNotification(notification.Body, message.Data);
        }
        /**
         * Called when message is received.
         */

        // [START receive_message]
        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.
            Android.Util.Log.Debug(TAG, "From: " + message.From);
            Android.Util.Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
        }
示例#21
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);

            Console.WriteLine("Received: " + message);
            string messageBody = (message.GetNotification() != null) ?
                                 message.GetNotification().Body :
                                 message.Data.Values.First(); // NOTE: test messages sent via the Azure portal will be received here

            if (NetworkDatabase.InBackground)
            {
                SendLocalNotification(messageBody);
            }
            else
            {
                MessagingCenter.Send <object, string>(this, App.NotificationReceivedKey, messageBody);
            }
        }
示例#22
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            var title       = message.GetNotification().Title;
            var body        = message.GetNotification().Body;
            var clickAction = message.GetNotification().ClickAction;

            Dictionary <string, string> data = new Dictionary <string, string>();

            foreach (string key in message.Data.Keys)
            {
                string value = message.Data[key];
                Logger.CmWrite(TAG, $"key: {key}, value:{value}");
                data.Add(key, value);
            }

            Logger.CmWrite(TAG, $"OnMessageReceived: {title}, {body}, {clickAction}");
            MainActivity.CmNotify(title, body, clickAction, data);
        }
示例#23
0
        void showNotification(RemoteMessage message)
        {
            var intent = new Intent(this, typeof(MainActivity));

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

            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.icon)
                                      .SetContentTitle(message.GetNotification().Title ?? "from Firebase")
                                      .SetContentText(message.GetNotification().Body)
                                      .SetAutoCancel(true)
                                      .SetContentIntent(pendingIntent);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0, notificationBuilder.Build());
        }
        public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Debug(TAG, "From: " + message.From);

            var      body         = message.GetNotification().Body;
            var      head         = message.GetNotification().Title;
            var      timestamp    = message.SentTime;
            double   seconds      = timestamp / 1000;
            DateTime utcConverted = new DateTime(1970, 1, 1, 9, 0, 0, DateTimeKind.Utc).AddSeconds(seconds).ToLocalTime();

            string[] lines = null;

            //알람시 logdata 에 작성
            var directory = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
            var filename  = Path.Combine(directory.ToString(), "LogData.txt");

            try // 기존 로그 데이터 불러옴
            {
                lines = File.ReadAllLines(filename);
            }
            catch (Exception)
            {
            }
            try // 기존 로그데이터 + 신규 로그데이터
            {
                using (var writer = new StreamWriter(System.IO.File.OpenWrite(filename)))
                {
                    writer.WriteLine("시간 : " + utcConverted.ToString("yy/MM/dd HH:mm:ss") + "%" + "제목 : " + head + "%" + "내용 : " + body);

                    for (int i = 0; i < lines.Length; i++)
                    {
                        writer.WriteLine(lines[i]);
                    }
                }
            }
            catch (Exception)
            {
            }



            Log.Debug(TAG, "Notification Message Body: " + body);
            SendNotification(head, body, message.Data);
        }
        public static FCMNotification ToFCMNotification(this RemoteMessage message)
        {
            var notification = message.GetNotification();

            return(new FCMNotification(
                       notification?.Body,
                       notification?.Title,
                       notification?.ImageUrl?.ToString(),
                       message.Data));
        }
 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);
     }
 }
示例#27
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Debug(TAG, "From: " + message.From);
            Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);

            if (!message.Data.GetEnumerator().MoveNext())
            {
                SendNotification(message.Data);
            }
        }
示例#28
0
        public override void OnMessageReceived(RemoteMessage p0)
        {
            base.OnMessageReceived(p0);
            var notification = p0.GetNotification();

            if (notification != null)
            {
                WorkspaceOne.Android.WorkspaceOne.processMessage(notification.Title, notification.Body, null);
            }
        }
示例#29
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);
            string messageBody = string.Empty;

            if (message.GetNotification() != null)
            {
                messageBody = message.GetNotification().Body;
            }

            // NOTE: test messages sent via the Azure portal will be received here
            else
            {
                messageBody = message.Data.Values.First();
            }

            // convert the incoming message to a local notification
            SendLocalNotification(messageBody);
        }
        public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);
            var body = message.GetNotification().Body;

            //var icon = message.GetNotification().Icon;
            //var title = message.GetNotification().Title;
            //var sound = message.GetNotification().Sound;
            SendNotification(body, message.Data);
        }