Skip to content

Commit fa91223

Browse files
committed
Cleanup notification if not shown in foreground to report status correctly
1 parent 8b2f7f5 commit fa91223

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

com.unity.mobile.notifications/Runtime/Android/Plugins/com/unity/androidnotifications/UnityNotificationManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,13 +643,24 @@ public void onReceive(Context context, Intent intent) {
643643
// Call the system notification service to notify the notification.
644644
protected static void notify(Context context, int id, Notification notification) {
645645
boolean showInForeground = notification.extras.getBoolean(KEY_SHOW_IN_FOREGROUND, true);
646+
boolean didShowNotification = false;
646647
if (!isInForeground() || showInForeground) {
648+
didShowNotification = true;
647649
getNotificationManager(context).notify(id, notification);
648650
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) synchronized (UnityNotificationManager.class) {
649651
mVisibleNotifications.add(Integer.valueOf(id));
650652
}
651653
}
652654

655+
if (!didShowNotification) {
656+
// if notification is not shown and not repeating, cleanup so it's status does not show as scheduled
657+
long repeatInterval = notification.extras.getLong(KEY_REPEAT_INTERVAL, -1);
658+
if (repeatInterval <= 0) {
659+
removeScheduledNotification(id);
660+
deleteExpiredNotificationIntent(context, String.valueOf(id));
661+
}
662+
}
663+
653664
try {
654665
mNotificationCallback.onSentNotification(notification);
655666
} catch (RuntimeException ex) {

0 commit comments

Comments
 (0)