@@ -76,31 +76,39 @@ public void SetNotificationRepeatInterval_TimeIsConvertedToUnixTimeAndBack()
76
76
Assert . AreEqual ( repeatInterval , n . RepeatInterval ) ;
77
77
}
78
78
79
+ AndroidNotification CreateNotificationWithAllParameters ( )
80
+ {
81
+ var notification = new AndroidNotification ( ) ;
82
+ notification . Title = "title" ;
83
+ notification . Text = "text" ;
84
+ notification . SmallIcon = "small_icon" ;
85
+ notification . FireTime = DateTime . Now ;
86
+ notification . RepeatInterval = new TimeSpan ( 0 , 0 , 5 ) ;
87
+ notification . LargeIcon = "large_icon" ;
88
+ notification . Style = NotificationStyle . BigTextStyle ;
89
+ notification . Color = new Color ( 0.2f , 0.4f , 0.6f , 1.0f ) ;
90
+ notification . Number = 15 ;
91
+ notification . ShouldAutoCancel = true ;
92
+ notification . UsesStopwatch = true ;
93
+ notification . Group = "group" ;
94
+ notification . GroupSummary = true ;
95
+ notification . GroupAlertBehaviour = GroupAlertBehaviours . GroupAlertChildren ;
96
+ notification . SortKey = "sorting" ;
97
+ notification . IntentData = "string for intent" ;
98
+ notification . ShowTimestamp = true ;
99
+ notification . ShowInForeground = false ; // this one defaults to true
100
+ notification . CustomTimestamp = new DateTime ( 2018 , 5 , 24 , 12 , 41 , 30 , 122 ) ;
101
+
102
+ return notification ;
103
+ }
104
+
79
105
[ Test ]
80
106
[ UnityPlatform ( RuntimePlatform . Android ) ]
81
107
public void BasicSerializeDeserializeNotification_AllParameters ( )
82
108
{
83
109
const int notificationId = 123 ;
84
110
85
- var original = new AndroidNotification ( ) ;
86
- original . Title = "title" ;
87
- original . Text = "text" ;
88
- original . SmallIcon = "small_icon" ;
89
- original . FireTime = DateTime . Now ;
90
- original . RepeatInterval = new TimeSpan ( 0 , 0 , 5 ) ;
91
- original . LargeIcon = "large_icon" ;
92
- original . Style = NotificationStyle . BigTextStyle ;
93
- original . Color = new Color ( 0.2f , 0.4f , 0.6f , 1.0f ) ;
94
- original . Number = 15 ;
95
- original . ShouldAutoCancel = true ;
96
- original . UsesStopwatch = true ;
97
- original . Group = "group" ;
98
- original . GroupSummary = true ;
99
- original . GroupAlertBehaviour = GroupAlertBehaviours . GroupAlertChildren ;
100
- original . SortKey = "sorting" ;
101
- original . IntentData = "string for intent" ;
102
- original . ShowTimestamp = true ;
103
- original . CustomTimestamp = new DateTime ( 2018 , 5 , 24 , 12 , 41 , 30 , 122 ) ;
111
+ var original = CreateNotificationWithAllParameters ( ) ;
104
112
105
113
var deserializedData = SerializeDeserializeNotification ( original , notificationId ) ;
106
114
@@ -118,14 +126,19 @@ AndroidNotificationIntentData SerializeDeserializeNotification(AndroidNotificati
118
126
}
119
127
120
128
AndroidNotificationIntentData SerializeDeserializeNotification ( AndroidJavaObject builder )
129
+ {
130
+ return SerializeDeserializeNotification ( builder , "serializeNotificationCustom" ) ;
131
+ }
132
+
133
+ AndroidNotificationIntentData SerializeDeserializeNotification ( AndroidJavaObject builder , string serializeMethod )
121
134
{
122
135
var javaNotif = builder . Call < AndroidJavaObject > ( "build" ) ;
123
136
var utilsClass = new AndroidJavaClass ( "com.unity.androidnotifications.UnityNotificationUtilities" ) ;
124
137
AndroidJavaObject serializedBytes ; // use java object, since we don't need the bytes, so don't waste time on marshalling
125
138
using ( var byteStream = new AndroidJavaObject ( "java.io.ByteArrayOutputStream" ) )
126
139
{
127
140
var dataStream = new AndroidJavaObject ( "java.io.DataOutputStream" , byteStream ) ;
128
- var didSerialize = utilsClass . CallStatic < bool > ( "serializeNotificationCustom" , javaNotif , dataStream ) ;
141
+ var didSerialize = utilsClass . CallStatic < bool > ( serializeMethod , javaNotif , dataStream ) ;
129
142
Assert . IsTrue ( didSerialize ) ;
130
143
dataStream . Call ( "close" ) ;
131
144
serializedBytes = byteStream . Call < AndroidJavaObject > ( "toByteArray" ) ;
@@ -165,6 +178,7 @@ void CheckNotificationsMatch(AndroidNotification original, AndroidNotification o
165
178
Assert . AreEqual ( original . SortKey , other . SortKey ) ;
166
179
Assert . AreEqual ( original . IntentData , other . IntentData ) ;
167
180
Assert . AreEqual ( original . ShowTimestamp , other . ShowTimestamp ) ;
181
+ Assert . AreEqual ( original . ShowInForeground , other . ShowInForeground ) ;
168
182
Assert . AreEqual ( original . CustomTimestamp , other . CustomTimestamp ) ;
169
183
}
170
184
@@ -296,6 +310,7 @@ public void NotificationSerialization_NotificationWithBinderObject()
296
310
297
311
var original = new AndroidNotification ( ) ;
298
312
original . FireTime = DateTime . Now . AddSeconds ( 2 ) ;
313
+ original . ShowInForeground = false ; // non default value
299
314
300
315
var builder = AndroidNotificationCenter . CreateNotificationBuilder ( notificationId , original , kChannelId ) ;
301
316
var extras = builder . Call < AndroidJavaObject > ( "getExtras" ) ;
@@ -306,6 +321,7 @@ public void NotificationSerialization_NotificationWithBinderObject()
306
321
var deserializedData = SerializeDeserializeNotification ( builder ) ;
307
322
308
323
Assert . AreEqual ( original . FireTime . ToString ( ) , deserializedData . Notification . FireTime . ToString ( ) ) ;
324
+ Assert . IsFalse ( deserializedData . Notification . ShowInForeground ) ;
309
325
var deserializedExtras = deserializedData . NativeNotification . Get < AndroidJavaObject > ( "extras" ) ;
310
326
var bitmapAfterSerialization = deserializedExtras . Call < AndroidJavaObject > ( "getParcelable" , "binder_item" ) ;
311
327
// bitmap is binder object and can't be parcelled, while our fallback custom serialization only preserves our stuff
0 commit comments