Forum Xamarin.Android

Pushing local notification in exact time not working (android)

JohnMizJohnMiz Member ✭✭
edited November 2018 in Xamarin.Android


I'm trying to set an alarm that will send a notification in exact time.

I followed this information:

And my code is

      private void PushNotificationEverydayInExactTime(int hour, int minute = 0)
               Intent intent = new Intent(this, typeof(NotificationReceiver));

               PendingIntent pendingIntent = PendingIntent.GetBroadcast(this, 100, intent, PendingIntentFlags.UpdateCurrent);

               AlarmManager alarmManager = GetSystemService(Context.AlarmService) as AlarmManager;

               Calendar calendar = Calendar.GetInstance(Java.Util.TimeZone.GetTimeZone("UTC"));
               calendar.TimeInMillis = Java.Lang.JavaSystem.CurrentTimeMillis();
               calendar.Set(CalendarField.HourOfDay, 10);
               calendar.Set(CalendarField.Minute, 50);

               alarmManager.SetInexactRepeating(AlarmType.RtcWakeup, calendar.TimeInMillis, AlarmManager.IntervalDay, pendingIntent);


It's not working because of the "calendar.TimeInMillis", when I set it to 100 or something small it's working.

But how do I make it notify every day in some time?


Best Answer

  • JohnMizJohnMiz ✭✭
    Accepted Answer

    Not exactly sure what the solution was but I removed this part:

    "calendar.TimeInMillis = Java.Lang.JavaSystem.CurrentTimeMillis();"

    Also, maybe I didn't wait long enough to see if the notification was received. Apparently, it takes a few seconds to receive the notification.


Sign In or Register to comment.