private static Notification GetNotification(Context ctx, int sessionId, NotificationOption not) { WorkshopDetail session = null; if (not.isWorkshop) session = Services.Workshop.GetWorkshopFromBookingLocal(sessionId); else session = Services.Session.GetSession(sessionId); var prefix = (not.isWorkshop) ? "" : "Session with "; Notification.Builder mBuilder = new Notification.Builder(ctx) .SetSmallIcon(Resource.Drawable.notificationIcon) .SetContentTitle(prefix + session.Title) .SetContentText(session.Time + " - " + session.DateHumanFriendly) .SetAutoCancel(true) .SetColor(ctx.Resources.GetColor(Resource.Color.primary)) .SetDefaults(NotificationDefaults.All) .SetStyle( new Notification.BigTextStyle().SetSummaryText(session.Title) .BigText(session.Time + " - " + session.DateHumanFriendly + System.Environment.NewLine + session.Room)); try { Looper.Prepare(); } catch (System.Exception ex) { } Intent resultIntent = new Intent(ctx, new ViewSessionActivity().Class); if (not.isWorkshop) resultIntent = new Intent(ctx, new ViewWorkshopActivity().Class); resultIntent.PutExtra("Id", sessionId); resultIntent.PutExtra("IsBooking", true); TaskStackBuilder stackBuilder = TaskStackBuilder.Create(ctx); stackBuilder.AddParentStack(new ViewWorkshopActivity().Class); stackBuilder.AddNextIntent(resultIntent); int identifier = (not.isWorkshop) ? 1 : 0; int notificationId = Integer.ParseInt(identifier + sessionId.ToString() + not.mins); PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(notificationId, PendingIntentFlags.UpdateCurrent); mBuilder.SetContentIntent(resultPendingIntent); return mBuilder.Build(); }
private static PendingIntent GetPendingIntent(Context ctx, Notification notification, NotificationOption not, int sessionId) { // Creates an explicit intent for an Activity in your app Intent notificationIntent = new Intent(ctx, typeof(NotificationPublisher)); int identifier = (not.isWorkshop) ? 1 : 0; int notificationId = Integer.ParseInt(identifier + sessionId.ToString() + not.mins); notificationIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId); notificationIntent.PutExtra(NotificationPublisher.NOTIFICATION, notification); return PendingIntent.GetBroadcast(ctx, notificationId, notificationIntent, PendingIntentFlags.UpdateCurrent); }
private static void CreateAlarmManager(Context ctx, Notification notification, DateTime date, NotificationOption not, int sessionId) { DateTime dtBasis = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); AlarmManager alarmManager = (AlarmManager) ctx.GetSystemService(Context.AlarmService); alarmManager.Set(AlarmType.RtcWakeup, (long) date.ToUniversalTime().Subtract(dtBasis).TotalMilliseconds, GetPendingIntent(ctx, notification, not, sessionId)); }