private void InstanceCheckLaunchedFromNotification(LaunchActivatedEventArgs e)
        {
            IDictionary <string, string> customData = null;

            _mutex.Lock();
            try
            {
                if (!IsInactive)
                {
                    customData = ParseLaunchString(e?.Arguments);
                }
            }
            finally
            {
                _mutex.Unlock();
            }
            if (customData != null)
            {
                PushNotificationReceived?.Invoke(null, new PushNotificationReceivedEventArgs()
                {
                    Title      = null,
                    Message    = null,
                    CustomData = customData
                });
            }
        }
Esempio n. 2
0
 private void OnPushNotificationReceivedHandler(PushNotificationChannel sender, WindowsPushNotificationReceivedEventArgs e)
 {
     if (e.NotificationType == PushNotificationType.Toast)
     {
         var content = e.ToastNotification.Content;
         MobileCenterLog.Debug(LogTag, $"Received push notification payload: {content.GetXml()}");
         if (ApplicationLifecycleHelper.Instance.IsSuspended)
         {
             MobileCenterLog.Debug(LogTag, "Application in background. Push callback will be called when user clicks the toast notification.");
         }
         else
         {
             var pushNotification = ParseMobileCenterPush(content);
             if (pushNotification != null)
             {
                 e.Cancel = true;
                 PushNotificationReceived?.Invoke(sender, pushNotification);
                 MobileCenterLog.Debug(LogTag, "Application in foreground. Intercept push notification and invoke push callback.");
             }
             else
             {
                 MobileCenterLog.Debug(LogTag, "Push ignored. It was not sent through Mobile Center.");
             }
         }
     }
     else
     {
         MobileCenterLog.Debug(LogTag, $"Push ignored. We only handle Toast notifications but PushNotificationType is '{e.NotificationType}'.");
     }
 }
Esempio n. 3
0
        public void HandlePushNotification(PushNotificationData notification)
        {
            int    action  = (int)notification["action"];
            string payload = (string)notification["payload"];

            PushNotificationReceived?.Invoke(this, new PushNotificationEventArgs(action, payload));
        }
Esempio n. 4
0
        public override void OnReceivedRemoteNotification(Dictionary <string, object> data)
        {
            string title   = (string)data["title"];
            string message = (string)data["body"];
            int    action  = (int)data["action"];
            string payload = (string)data["payload"];

            if (action == 1)
            {
                int lastMessageId = Int32.Parse(payload);
                AppController.Settings.LastMessageId = lastMessageId;
            }

            // Check if the app is in foreground
            // If not show an "heads up" notification, otherwhise notify an event
            if (!this.IsApplicationInForeground)
            {
                // Preparing notification to be shown to the user
                NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(Application.Context.ApplicationContext)
                    .SetSmallIcon(Resource.Drawable.ic_push)
                    .SetContentTitle(title)
                    .SetContentText(message)
                    .SetAutoCancel(true)
                    .SetSound(Android.Net.Uri.Parse(String.Format("android.resource://{0}/{1}",
                                                                  this.PackageName, Resource.Raw.sound_ding)))
                    .SetPriority((int)Android.App.NotificationPriority.High);

                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    mBuilder.SetVibrate(new long[0]);
                }

                // Setting the intent to be executed when the user tap the notification
                Intent notificationIntent = new Intent(this, typeof(MainActivity));
                notificationIntent.SetFlags(ActivityFlags.ReorderToFront);
                PendingIntent pendingIntent = PendingIntent.GetActivity(
                    Application.Context.ApplicationContext,
                    0,
                    notificationIntent,
                    PendingIntentFlags.UpdateCurrent);

                if (pendingIntent != null)
                {
                    mBuilder.SetContentIntent(pendingIntent);
                }

                NotificationManager mNotificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
                mNotificationManager.Notify(0, mBuilder.Build());
            }

            PushNotificationReceived?.Invoke(this, new PushEventArgs(action, payload));
        }
Esempio n. 5
0
 static Push()
 {
     _pushListener.OnPushNotificationReceivedAction = notification =>
     {
         var pushEventArgs = new PushNotificationReceivedEventArgs
         {
             Title      = notification.Title,
             Message    = notification.Message,
             CustomData = notification.CustomData
         };
         PushNotificationReceived?.Invoke(null, pushEventArgs);
     };
     AndroidPush.SetListener(_pushListener);
 }
Esempio n. 6
0
File: Push.cs Progetto: ManjuBP/.net
 static Push()
 {
     _pushDelegate.OnPushNotificationReceivedAction = notification =>
     {
         var pushEventArgs = new PushNotificationReceivedEventArgs
         {
             Title      = notification.Title,
             Message    = notification.Message,
             CustomData = notification.CustomData?.ToDictionary(i => i.Key.ToString(), i => i.Value.ToString())
         };
         PushNotificationReceived?.Invoke(null, pushEventArgs);
     };
     MSPush.SetDelegate(_pushDelegate);
 }
Esempio n. 7
0
 static Push()
 {
     _pushDelegate.OnPushNotificationReceivedAction = notification =>
     {
         var pushEventArgs = new PushNotificationReceivedEventArgs
         {
             Title      = notification.Title,
             Message    = notification.Message,
             CustomData = NSDictionaryToDotNet(notification.CustomData)
         };
         PushNotificationReceived?.Invoke(null, pushEventArgs);
     };
     MSPush.SetDelegate(_pushDelegate);
 }
Esempio n. 8
0
        public void InstanceCheckLaunchedFromNotification(string args)
        {
            IDictionary <string, string> customData = null;

            using (_mutex.GetLock())
            {
                if (!IsInactive)
                {
                    customData = ParseLaunchString(args);
                }
            }
            if (customData != null)
            {
                PushNotificationReceived?.Invoke(null, new PushNotificationReceivedEventArgs
                {
                    Title      = null,
                    Message    = null,
                    CustomData = customData
                });
            }
        }
Esempio n. 9
0
        public override void ReceivedRemoteNotification(Dictionary <string, object> data)
        {
            string title   = (string)data["title"];
            string message = (string)data["body"];
            int    action  = (int)data["action"];
            string payload = (string)data["payload"];

            if (action == 1)
            {
                int lastMessageId = Int32.Parse(payload);
                AppController.Settings.LastMessageId = lastMessageId;
            }

            // Check if the app is in foreground
            if (!this.IsApplicationInForeground)
            {
                // "Heads-up" notification is handled by iOS so we just need to handle what
                // to do when the app is "restarted" or "resumed"
                HandleRemoteNotificationLaunching(
                    () =>
                {
                    this.Window = new UIWindow(UIScreen.MainScreen.Bounds);
                    this.Window.RootViewController = new MainViewController();
                    this.Window.MakeKeyAndVisible();
                },
                    () =>
                {
                    var c = this.Window.RootViewController;
                    if (c is AdMaiora.AppKit.UI.App.UIMainViewController)
                    {
                        ((AdMaiora.AppKit.UI.App.UIMainViewController)c).RemoteNotification(new UIBundle());
                    }
                });
            }

            PushNotificationReceived?.Invoke(this, new PushEventArgs(action, payload));
        }
 protected virtual void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
 {
     PushNotificationReceived?.Invoke(sender, args);
 }