Skip to content

Commit

Permalink
Merge pull request #1458 from anchorit3/dev
Browse files Browse the repository at this point in the history
Fix improper storage of notification when not passing an AndroidNotification initially
  • Loading branch information
aritchie authored Apr 23, 2024
2 parents a3458bf + c25bdd5 commit a5e6b62
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion samples/Sample.Maui/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARMS" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARMS" android:maxSdkVersion="33" />
<uses-permission android:name="android.permission.USE_EXACT_ALARMS" />

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
Expand Down
34 changes: 17 additions & 17 deletions src/Shiny.Notifications/Platforms/Android/NotificationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,46 +138,46 @@ public async Task<AccessState> RequestAccess(AccessRequestFlags access)
public async Task Send(Notification notification)
{
notification.AssertValid();
var android = notification.TryToNative<AndroidNotification>();
var androidNotification = notification.TryToNative<AndroidNotification>();

// TODO: should I cancel an existing id if the user is setting it?
if (notification.Id == 0)
notification.Id = this.settings.IncrementValue("NotificationId");
if (androidNotification.Id == 0)
androidNotification.Id = this.settings.IncrementValue("NotificationId");

var channelId = notification.Channel ?? Channel.Default.Identifier;
var channelId = androidNotification.Channel ?? Channel.Default.Identifier;
var channel = this.channelManager.Get(channelId);
if (channel == null)
throw new InvalidProgramException("No channel found for " + channelId);

var builder = this.manager.CreateNativeBuilder(android, channel!);
var builder = this.manager.CreateNativeBuilder(androidNotification, channel!);

if (notification.Geofence != null)
if (androidNotification.Geofence != null)
{
await this.geofenceManager.StartMonitoring(new GeofenceRegion(
AndroidNotificationProcessor.GetGeofenceId(notification),
notification.Geofence!.Center!,
notification.Geofence!.Radius!
AndroidNotificationProcessor.GetGeofenceId(androidNotification),
androidNotification.Geofence!.Center!,
androidNotification.Geofence!.Radius!
));
}
else if (notification.RepeatInterval != null)
else if (androidNotification.RepeatInterval != null)
{
// calc first date if repeating interval
notification.ScheduleDate = notification.RepeatInterval!.CalculateNextAlarm();
androidNotification.ScheduleDate = androidNotification.RepeatInterval!.CalculateNextAlarm();
}

if (notification.ScheduleDate == null && notification.Geofence == null)
if (androidNotification.ScheduleDate == null && androidNotification.Geofence == null)
{
var native = builder.Build();
this.manager.NativeManager.Notify(notification.Id, native);
this.manager.NativeManager.Notify(androidNotification.Id, native);
}
else
{
// ensure a channel is set
notification.Channel = channel!.Identifier;
this.repository.Set(notification);
androidNotification.Channel = channel!.Identifier;
this.repository.Set(androidNotification);

if (notification.ScheduleDate != null)
this.manager.SetAlarm(notification);
if (androidNotification.ScheduleDate != null)
this.manager.SetAlarm(androidNotification);
}
}

Expand Down

0 comments on commit a5e6b62

Please sign in to comment.