void ParsePush_ParsePushNotificationReceived(object sender, ParsePushNotificationEventArgs e)
        {
            try{
            if (e.Payload.ContainsKey ("alert")&&e.Payload.ContainsKey ("message")&&e.Payload.ContainsKey ("topic")) {

                var intent = new Intent (ApplicationContext, typeof(MainScreenActivity));

                intent.PutExtra ("topic", e.Payload ["topic"].ToString());
                // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
                const int pendingIntentId = 0;
                PendingIntent pendingIntent =
                    PendingIntent.GetActivity (ApplicationContext, pendingIntentId, intent, PendingIntentFlags.OneShot);

                Vibrator v = (Vibrator)GetSystemService (VibratorService);
                v.Vibrate (300);
                System.Diagnostics.Debug.WriteLine (e.Payload["alert"]);
                System.Diagnostics.Debug.WriteLine (e.Payload["message"]);
                System.Diagnostics.Debug.WriteLine (e.Payload["topic"]);

                notificationBuilder.SetContentIntent (pendingIntent);
                notificationBuilder.SetContentTitle (e.Payload["alert"].ToString());
                notificationBuilder.SetContentText (e.Payload["message"].ToString());
                var notification = notificationBuilder.Build ();
                    notification.Flags = NotificationFlags.AutoCancel;
                notificationManager.Notify (pendingIntentId, notification);
            }
            }
            catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
            }
        }
		public void PushNotificationHandler (object sender, ParsePushNotificationEventArgs args)
		{
			var payload = args.Payload;
			object objectId;
			object alertMessage;
			if (payload.TryGetValue (Const.OBJECT_ID, out objectId)) {
				if (payload.TryGetValue (Const.ALERT_DICT_KEY, out alertMessage)) {
					generateNotification (alertMessage.ToString (), (string)objectId);
				}
			}
		}
Example #3
0
        void ParsePush_ParsePushNotificationReceived(object sender, ParsePushNotificationEventArgs e)
        {
            var intent = new Intent(Context, typeof(MainActivity));
            PendingIntent pendingIntent = PendingIntent.GetActivity(Context, 0, intent, PendingIntentFlags.OneShot);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(Context)
                .SetContentTitle("Doorduino")
                .SetAutoCancel(true)
                .SetContentText(e.Payload["alert"].ToString())
                .SetPriority((int)NotificationPriority.High)
                .SetVisibility((int)NotificationVisibility.Public)
                .SetCategory(Notification.CategoryAlarm)
                .SetContentIntent(pendingIntent)
                .SetDefaults((int)(NotificationDefaults.Sound | NotificationDefaults.Vibrate))
                .SetSmallIcon(Android.Resource.Drawable.IcMenuSend);

            var notification = builder.Build();
            var notificationManager = (NotificationManager)Context.GetSystemService(Context.NotificationService);
            notificationManager.Notify(0, notification);
        }
    /// <summary>
    /// Attach this method to <see cref="ParsePush.ParsePushNotificationReceived"/> to utilize a
    /// default handler for push notification.
    /// </summary>
    /// <remarks>
    /// This handler will try to get the launcher <see cref="Activity"/> and application icon, then construct a
    /// <see cref="Notification"/> out of them. It uses push payload's <c>title</c> and <c>alert</c> as the
    /// <see cref="Notification.ContentView"/> title and text.
    /// </remarks>
    /// <param name="sender"></param>
    /// <param name="args"></param>
    public static void DefaultParsePushNotificationReceivedHandler(object sender, ParsePushNotificationEventArgs args) {
      IDictionary<string, object> pushData = args.Payload;
      Context context = Application.Context;

      if (pushData == null || (!pushData.ContainsKey("alert") && !pushData.ContainsKey("title"))) {
        return;
      }

      string title = pushData.ContainsKey("title") ? pushData["title"] as string : ManifestInfo.DisplayName;
      string alert = pushData.ContainsKey("alert") ? pushData["alert"] as string : "Notification received.";
      string tickerText = title + ": " + alert;

      Random random = new Random();
      int contentIntentRequestCode = random.Next();

      Intent activityIntent = ManifestInfo.LauncherIntent;
      PendingIntent pContentIntent = PendingIntent.GetActivity(context, contentIntentRequestCode, activityIntent, PendingIntentFlags.UpdateCurrent);

      NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
        .SetContentTitle(new Java.Lang.String(title))
        .SetContentText(new Java.Lang.String(alert))
        .SetTicker(new Java.Lang.String(tickerText))
        .SetSmallIcon(ManifestInfo.PushIconId)
        .SetContentIntent(pContentIntent)
        .SetAutoCancel(true)
        .SetDefaults(NotificationDefaults.All);

      Notification notification = builder.Build();
      NotificationManager manager = context.GetSystemService(Context.NotificationService) as NotificationManager;
      int notificationId = (int)DateTime.UtcNow.Ticks;

      try {
        manager.Notify(notificationId, notification);
      } catch (Exception) {
        // Some phones throw exception for unapproved vibration.
        notification.Defaults = NotificationDefaults.Lights | NotificationDefaults.Sound;
        manager.Notify(notificationId, notification);
      }
    }
Example #5
0
		void HandleParsePushNotificationReceived (object sender, ParsePushNotificationEventArgs e)
		{

		}
Example #6
0
        /// <summary>
        /// Attach this method to <see cref="ParsePush.ParsePushNotificationReceived"/> to utilize a
        /// default handler for push notification.
        /// </summary>
        /// <remarks>
        /// This handler will try to get the launcher <see cref="Activity"/> and application icon, then construct a
        /// <see cref="Notification"/> out of them. It uses push payload's <c>title</c> and <c>alert</c> as the
        /// <see cref="Notification.ContentView"/> title and text.
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public static void DefaultParsePushNotificationReceivedHandler(object sender, ParsePushNotificationEventArgs args)
        {
            IDictionary <string, object> pushData = args.Payload;
            Context context = Application.Context;

            if (pushData == null || (!pushData.ContainsKey("alert") && !pushData.ContainsKey("title")))
            {
                return;
            }

            string title      = pushData.ContainsKey("title") ? pushData["title"] as string : ManifestInfo.DisplayName;
            string alert      = pushData.ContainsKey("alert") ? pushData["alert"] as string : "Notification received.";
            string tickerText = title + ": " + alert;

            Random random = new Random();
            int    contentIntentRequestCode = random.Next();

            Intent        activityIntent = ManifestInfo.LauncherIntent;
            PendingIntent pContentIntent = PendingIntent.GetActivity(context, contentIntentRequestCode, activityIntent, PendingIntentFlags.UpdateCurrent);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                                                 .SetContentTitle(new Java.Lang.String(title))
                                                 .SetContentText(new Java.Lang.String(alert))
                                                 .SetTicker(new Java.Lang.String(tickerText))
                                                 .SetSmallIcon(ManifestInfo.PushIconId)
                                                 .SetContentIntent(pContentIntent)
                                                 .SetAutoCancel(true)
                                                 .SetDefaults(NotificationDefaults.All);

            Notification        notification = builder.Build();
            NotificationManager manager      = context.GetSystemService(Context.NotificationService) as NotificationManager;
            int notificationId = (int)DateTime.UtcNow.Ticks;

            try {
                manager.Notify(notificationId, notification);
            } catch (Exception) {
                // Some phones throw exception for unapproved vibration.
                notification.Defaults = NotificationDefaults.Lights | NotificationDefaults.Sound;
                manager.Notify(notificationId, notification);
            }
        }
 private static void ParsePush_ParsePushNotificationReceived(object sender, ParsePushNotificationEventArgs e)
 {
    
 }