Skip to content

Commit 5f3fdbe

Browse files
committed
Split CreateNotificationBuilder with id into two
1 parent 2fe5e95 commit 5f3fdbe

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

com.unity.mobile.notifications/Runtime/Android/AndroidNotificationCenter.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,18 @@ public static AndroidJavaObject CreateNotificationBuilder(AndroidNotification no
872872
/// <param name="channelId">Channel id</param>
873873
/// <returns>A proxy object for created Notification.Builder</returns>
874874
public static AndroidJavaObject CreateNotificationBuilder(int id, AndroidNotification notification, string channelId)
875+
{
876+
AndroidJavaObject builder, extras;
877+
CreateNotificationBuilder(notification, channelId, out builder, out extras);
878+
if (extras != null)
879+
{
880+
s_Jni.Bundle.PutInt(extras, s_Jni.NotificationManager.KEY_ID, id);
881+
extras.Dispose();
882+
}
883+
return builder;
884+
}
885+
886+
static void CreateNotificationBuilder(AndroidNotification notification, string channelId, out AndroidJavaObject notificationBuilder, out AndroidJavaObject extras)
875887
{
876888
long fireTime = notification.FireTime.ToLong();
877889
if (fireTime < 0L)
@@ -881,7 +893,7 @@ public static AndroidJavaObject CreateNotificationBuilder(int id, AndroidNotific
881893

882894
// NOTE: JNI calls are expensive, so we avoid calls that set something that is also a default
883895

884-
var notificationBuilder = s_Jni.NotificationManager.CreateNotificationBuilder(channelId);
896+
notificationBuilder = s_Jni.NotificationManager.CreateNotificationBuilder(channelId);
885897
s_Jni.NotificationManager.SetNotificationIcon(notificationBuilder, s_Jni.NotificationManager.KEY_SMALL_ICON, notification.SmallIcon);
886898
if (!string.IsNullOrEmpty(notification.LargeIcon))
887899
s_Jni.NotificationManager.SetNotificationIcon(notificationBuilder, s_Jni.NotificationManager.KEY_LARGE_ICON, notification.LargeIcon);
@@ -919,17 +931,12 @@ public static AndroidJavaObject CreateNotificationBuilder(int id, AndroidNotific
919931
if (notification.GroupAlertBehaviour != GroupAlertBehaviours.GroupAlertAll) // All is default value
920932
s_Jni.NotificationManager.SetNotificationGroupAlertBehavior(notificationBuilder, (int)notification.GroupAlertBehaviour);
921933

922-
using (var extras = s_Jni.NotificationBuilder.GetExtras(notificationBuilder))
923-
{
924-
s_Jni.Bundle.PutInt(extras, s_Jni.NotificationManager.KEY_ID, id);
925-
s_Jni.Bundle.PutLong(extras, s_Jni.NotificationManager.KEY_REPEAT_INTERVAL, notification.RepeatInterval.ToLong());
926-
s_Jni.Bundle.PutLong(extras, s_Jni.NotificationManager.KEY_FIRE_TIME, fireTime);
927-
s_Jni.Bundle.PutBoolean(extras, s_Jni.NotificationManager.KEY_SHOW_IN_FOREGROUND, notification.ShowInForeground);
928-
if (!string.IsNullOrEmpty(notification.IntentData))
929-
s_Jni.Bundle.PutString(extras, s_Jni.NotificationManager.KEY_INTENT_DATA, notification.IntentData);
930-
}
931-
932-
return notificationBuilder;
934+
extras = s_Jni.NotificationBuilder.GetExtras(notificationBuilder);
935+
s_Jni.Bundle.PutLong(extras, s_Jni.NotificationManager.KEY_REPEAT_INTERVAL, notification.RepeatInterval.ToLong());
936+
s_Jni.Bundle.PutLong(extras, s_Jni.NotificationManager.KEY_FIRE_TIME, fireTime);
937+
s_Jni.Bundle.PutBoolean(extras, s_Jni.NotificationManager.KEY_SHOW_IN_FOREGROUND, notification.ShowInForeground);
938+
if (!string.IsNullOrEmpty(notification.IntentData))
939+
s_Jni.Bundle.PutString(extras, s_Jni.NotificationManager.KEY_INTENT_DATA, notification.IntentData);
933940
}
934941

935942
internal static AndroidNotificationIntentData GetNotificationData(AndroidJavaObject notificationObj)

0 commit comments

Comments
 (0)