Rohan Fulzele

Rohan Fulzele

  • NA
  • 112
  • 2.4k

Scheduled notification not working in Xamarin android 9.0

Dec 24 2019 9:26 AM
Hi,
Whenever I am using Alarm Manager in my Local Notification code,it is working fine with Android version 8.0 and below. But ,
its not working for Android version 9.0.
Alarm Manager Code ::
var intent = CreateIntent(id);
var localNotification = new LocalNotification();
localNotification.Title = title;
localNotification.Body = body;
localNotification.Id = id;
localNotification.NotifyTime = notifyTime;
if (_notificationIconId != 0)
{
localNotification.IconId = _notificationIconId;
}
else
{
localNotification.IconId = Resource.Drawable.notification_bg;
}
var serializedNotification = SerializeNotification(localNotification);
intent.PutExtra(ScheduledAlarmHandler.LocalNotificationKey, serializedNotification);
Random generator = new Random();
_randomNumber = generator.Next(100000, 999999).ToString("D6");
var pendingIntent = PendingIntent.GetBroadcast(Application.Context, Convert.ToInt32(_randomNumber), intent, PendingIntentFlags.Immutable);
var alarmManager = GetAlarmManager();
alarmManager.Set(AlarmType.RtcWakeup, totalMilliSeconds, pendingIntent);
And, when I am implementing the same code with Notification Manager using ChannelID . So, the notification is popping up in
Android Version 9.0 and below.
But, if I want to set a particular delivery time to show up the Notification, then it doesn't work here. It delivers immediately.
Notification Manager Code ::
PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, pendingIntentId, intent, PendingIntentFlags.Immutable);
NotificationCompat.Builder builder = new NotificationCompat.Builder(Application.Context, channelId)
.SetVibrate(new long[] { 0, 100 })
.SetPriority(1)
.SetContentIntent(pendingIntent)
.SetContentTitle(title)
.SetContentText(body)
.SetWhen(totalMilliSeconds)
.SetSmallIcon(Resource.Drawable.notification_bg)
.SetDefaults((int)NotificationDefaults.Sound | (int)NotificationDefaults.Vibrate);
Notification notification = builder.Build();
manager.Notify(channelId, messageId, notification);
So, is there a way so that I can implement this in Android Version 9.0 and below???

Answers (2)