-
-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot send local notification with a ScheduleDate set using 3.2.4 #1406
Comments
Can you share your android manifest |
Previous versions of local notifications used shiny jobs which caused delays. V3 uses the alarm which needs a permission request. Try the extension off INotificationManager called RequestRequiredAccess(Notification notification) |
I tried calling RequestRequiredAccess with a notification that had ScheduleDate set and I got NullReferenceException. I copied the extension method so I could run it locally.
The call to RequestAccess sees the following callback to MainActivity.OnRequestPermissionsResult
In one of my debug scenarios the channel had not been created. That throws a NullReferenceException when trying to read Once the code runs on a device with the Channel I get an AccessState of Restricted.If I remove the Channel then the AccessRequestFlags.TimeSensitivity flag is not set and I get AccessState of Available. |
This one is going to require some fiddling. Android 14 (13 a bit) changes the way the alarm permission works. |
Hi, @munkii, @aritchie
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="33" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
if (!this.Alarms.CanScheduleExactAlarms())
{
var intent = new Android.Content.Intent(Android.Provider.Settings.ActionRequestScheduleExactAlarm);
Application.Current.Context.StartActivity(intent);
}
var list = await notificationManager.GetPendingNotifications();
var pendingNotificationsCount = list.Count(); // result is 0, but I scheduled notifications in future :( so I checked implementation of public Task<IList<Notification>> GetPendingNotifications()
=> Task.FromResult((IList<Notification>)this.repository.GetList<AndroidNotification>().OfType<Notification>().ToList()); then if pending notifications are coming from public async Task Send(Notification notification)
{
notification.AssertValid();
var android = notification.TryToNative<AndroidNotification>();
(...)
if (notification.ScheduleDate == null && notification.Geofence == null)
{
var native = builder.Build();
this.manager.NativeManager.Notify(notification.Id, native);
}
else
{
// ensure a channel is set
notification.Channel = channel!.Identifier;
this.repository.Set(notification);
if (notification.ScheduleDate != null)
this.manager.SetAlarm(notification);
}
} then we can see that into repository we store generic Notification type instead of AndroidNotification so I stored it as well. I added after //re-asign android variable because we did manipulation from the moment when it was defined
android = notification.TryToNative<AndroidNotification>();
this.repository.Set(android); and magic just happened - Scheduled Notifications started to works! I'm not sure how it should be, maybe However I hope it can help you to understand better problem and solve it in plugin :) |
@anchorit3 while I appreciate the effort. Most of the work is done in the 4.0 branch. The issue isn't really with the "making it happen", but with how much of a mess the permissions have gotten now due to this additional permission. I'm working on that part, but the plugin will do all of the permissions properly in the future. |
This is still an issue for us even when using 3.3.3. I can ask the Android AlarmService if i can schedule exact alarms via the
However when it comes time to send the notification and I call Shiny I get
I looked at the implmentation of NotifcationManager RequestAccess and had a look at starting the Are these exact notifications best left alone for now. Should wait for 4.0? Will 4.0 be MAUI only? |
It's still an issue because I haven't fixed it. I'll get to this when I can, but it isn't a 30 second fix. Fixes at this point are set for 4.0 which will be .NET8+ only |
Component/Nuget
Notifications (Shiny.Notifications)
What operating system(s) are effected?
Version(s) of Operation Systems
Android 12, 13 and 14 and 9 (Physical devices)
Hosting Model
Steps To Reproduce
Using Shiny 3.2.4 set the ScheduleDate on the local notifcation and try and send it. Notifcation does not appear
Expected Behavior
I'd expect to see a scheduled notification or an error.
Permission issues with Android 14 wouldn't be that surprising and I have logged an issue with Xamarin Essentials FWIW
Actual Behavior
No error and no Notification. If I do not set the ScheduleData the notifcation happens immediately without issue
Exception or Log output
No response
Code Sample
AndroidManifest
AssemblyInfo Permission attributes
Code of Conduct
The text was updated successfully, but these errors were encountered: