Skip to content

Commit 9c64f53

Browse files
committed
Refactor scheduling to separate method
1 parent 5db1a59 commit 9c64f53

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,7 @@ public void scheduleNotification(Notification.Builder notificationBuilder) {
274274

275275
if (intent != null) {
276276
UnityNotificationManager.saveNotification(mContext, notificationBuilder.build());
277-
278-
// rebuild here, because we're setting content intent (which can't be saved)
279-
notification = buildNotificationForSending(mContext, mOpenActivity, notificationBuilder);
280-
mScheduledNotifications.put(Integer.valueOf(id), notification);
281-
intent.putExtra(KEY_NOTIFICATION_ID, id);
282-
283-
PendingIntent broadcast = getBroadcastPendingIntent(mContext, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
284-
UnityNotificationManager.scheduleNotificationIntentAlarm(mContext, repeatInterval, fireTime, broadcast);
277+
notification = scheduleAlarmWithNotification(notificationBuilder, intent, fireTime);
285278
}
286279
}
287280

@@ -293,6 +286,21 @@ public void scheduleNotification(Notification.Builder notificationBuilder) {
293286
}
294287
}
295288

289+
Notification scheduleAlarmWithNotification(Notification.Builder notificationBuilder, Intent intent, long fireTime) {
290+
Bundle extras = notificationBuilder.getExtras();
291+
int id = extras.getInt(KEY_ID, -1);
292+
long repeatInterval = extras.getLong(KEY_REPEAT_INTERVAL, -1);
293+
// fireTime not taken from notification, because we may have adjusted it
294+
295+
Notification notification = buildNotificationForSending(mContext, mOpenActivity, notificationBuilder);
296+
mScheduledNotifications.put(Integer.valueOf(id), notification);
297+
intent.putExtra(KEY_NOTIFICATION_ID, id);
298+
299+
PendingIntent broadcast = getBroadcastPendingIntent(mContext, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
300+
UnityNotificationManager.scheduleNotificationIntentAlarm(mContext, repeatInterval, fireTime, broadcast);
301+
return notification;
302+
}
303+
296304
protected static Notification buildNotificationForSending(Context context, Class openActivity, Notification.Builder builder) {
297305
int id = builder.getExtras().getInt(KEY_ID, -1);
298306
Intent openAppIntent = buildOpenAppIntent(context, openActivity);

0 commit comments

Comments
 (0)