Пример #1
0
        protected override void OnMessage(Context context, Intent intent)
        {
            //PowerManager.WakeLock sWakeLock;
            //var pm = PowerManager.FromContext(context);
            //sWakeLock = pm.NewWakeLock(WakeLockFlags.Partial, "GCM Broadcast Reciever Tag");
            //sWakeLock.Acquire();
            var msg = new StringBuilder();

            if (intent != null && intent.Extras != null)
            {
                foreach (var key in intent.Extras.KeySet())
                {
                    msg.AppendLine(key + "=" + intent.Extras.Get(key));
                }
                string messageText = intent.Extras.GetString("message");
                if (!string.IsNullOrEmpty(messageText))
                {
                    var recdMessage = messageText;
                    Common.Helpers.Settings.LastMessage = recdMessage;
                    PushNoticationMessage loginAttemptMessage = JsonConvert.DeserializeObject <PushNoticationMessage>(recdMessage);
                    PlatformPushNotificationImplementation.Platform.PushNotificationReceived(recdMessage, recdMessage);
                    CreateNotification(loginAttemptMessage);
                }
            }
            //sWakeLock.Release();
        }
Пример #2
0
 private async Task ProcessNotification(ReceivedMessageEventArgs e)
 {
     if (e != null && e.Content != null)
     {
         PushNoticationMessage recdMessage = JsonConvert.DeserializeObject <PushNoticationMessage>(e.Content);
         await NavigationService.NavigateAsync("/Index/Navigation/Home");
     }
 }
Пример #3
0
        public override void OnMessageReceived(string from, Bundle data)
        {
            Log.Info(AppConstants.TAG, "Message Received From " + from);
            var recdMessage = data.GetString("message");

            Settings.Current.LastMessage = recdMessage;
            PushNoticationMessage loginAttemptMessage = JsonConvert.DeserializeObject <PushNoticationMessage>(recdMessage);

            //PlatformPushNotificationImplementation.Platform.PushNotificationReceived(recdMessage, recdMessage);
            Log.Info(AppConstants.TAG, "Creating Local Notification");
            CreateNotification(loginAttemptMessage);
            Log.Info(AppConstants.TAG, "Created Local Notification");
        }
Пример #4
0
 void CreateNotification(PushNoticationMessage pushMessage)
 {
     try
     {
         // Get the notifications manager:
         NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
         // Instantiate the notification builder:
         //TODO: Get the Name of  the App from Manifest
         Notification.Builder builder = new Notification.Builder(this)
                                        .SetContentTitle("Quick Task")
                                        .SetContentText(pushMessage.Title)
                                        .SetAutoCancel(true)
                                        .SetSmallIcon(Resource.Drawable.icon)
                                        .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon));
         builder.SetVisibility(NotificationVisibility.Public);
         builder.SetPriority((int)NotificationPriority.High);
         builder.SetCategory(Notification.CategoryMessage);
         //Setup an intent for the Main Activity:
         Intent secondIntent = new Intent(this, typeof(MainActivity));
         secondIntent.PutExtra("recdMessage", Settings.Current.LastMessage);
         // Pressing the Back button in SecondActivity exits the app:
         Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(this);
         // Add the back stack for the intent:
         stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
         // Push the intent (that starts SecondActivity) onto the stack. The
         // pending intent can be used only once (one shot):
         stackBuilder.AddNextIntent(secondIntent);
         const int     pendingIntentId = 0;
         PendingIntent pendingIntent   = stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot);
         builder.SetContentIntent(pendingIntent);
         // Build the notification:
         Notification notification = builder.Build();
         notification.Defaults |= NotificationDefaults.Sound;
         // Notification ID used for all notifications in this app.
         // Reusing the notification ID prevents the creation of
         // numerous different notifications as the user experiments
         // with different notification settings -- each launch reuses
         // and updates the same notification.
         const int notificationId = 6;
         // Launch notification:
         notificationManager.Notify(notificationId, notification);
         Log.Info(AppConstants.TAG, "Local Notification Sent");
     }
     catch (Exception ex)
     {
         Log.Info(AppConstants.TAG, "Local Notify Failed with " + ex.Message);
     }
 }
Пример #5
0
        void CreateNotification(PushNoticationMessage pushedMessage)
        {
            // Get the notifications manager:
            NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

            // Instantiate the notification builder:
            Notification.Builder builder = new Notification.Builder(this)
                                           .SetContentTitle("WK Authenticator")
                                           .SetContentText(pushedMessage.Title)
                                           .SetAutoCancel(true)
                                           .SetSmallIcon(Resource.Drawable.icon)
                                           .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon));
            builder.SetVisibility(NotificationVisibility.Public);
            builder.SetPriority((int)NotificationPriority.High);
            builder.SetCategory(Notification.CategoryMessage);
            //Add Message Information to the Main Activity Intent - This will be shown on Tap Of the Notified Message
            Intent secondIntent = new Intent(this, typeof(MainActivity));

            // Pass the current notification string value to SecondActivity
            secondIntent.PutExtra("recdMessage", Common.Helpers.Settings.LastMessage);
            // Pressing the Back button in SecondActivity exits the app:
            Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(this);
            // Add the back stack for the intent:
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            // Push the intent (that starts SecondActivity) onto the stack. The
            // pending intent can be used only once (one shot):
            stackBuilder.AddNextIntent(secondIntent);
            const int     pendingIntentId = 0;
            PendingIntent pendingIntent   = stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot);

            builder.SetContentIntent(pendingIntent);
            // Build the notification:
            Notification notification = builder.Build();

            notification.Defaults |= NotificationDefaults.Sound;
            // Notification ID used for all notifications in this app.
            // Reusing the notification ID prevents the creation of numerous different notifications as the user experiments with different notification settings -- each launch reuses
            // and updates the same notification.
            const int notificationId = 0;

            // Launch notification:
            notificationManager.Notify(notificationId, notification);
        }