29
29
import static com .unity .androidnotifications .UnityNotificationManager .KEY_NOTIFICATION ;
30
30
import static com .unity .androidnotifications .UnityNotificationManager .KEY_REPEAT_INTERVAL ;
31
31
import static com .unity .androidnotifications .UnityNotificationManager .KEY_SMALL_ICON ;
32
+ import static com .unity .androidnotifications .UnityNotificationManager .SHOW_IN_FOREGROUND ;
32
33
import static com .unity .androidnotifications .UnityNotificationManager .TAG_UNITY ;
33
34
34
35
public class UnityNotificationUtilities {
35
36
// magic stands for "Unity Mobile Notifications Notification"
36
37
private static final byte [] UNITY_MAGIC_NUMBER = new byte [] { 'U' , 'M' , 'N' , 'N' };
37
38
private static final byte [] UNITY_MAGIC_NUMBER_PARCELLED = new byte [] { 'U' , 'M' , 'N' , 'P' };
38
- private static final int NOTIFICATION_SERIALIZATION_VERSION = 0 ;
39
+ private static final int NOTIFICATION_SERIALIZATION_VERSION = 1 ;
39
40
private static final int INTENT_SERIALIZATION_VERSION = 0 ;
40
41
41
42
private static final String SAVED_NOTIFICATION_PRIMARY_KEY = "data" ;
@@ -144,6 +145,7 @@ private static boolean serializeNotificationCustom(Notification notification, Da
144
145
out .writeBoolean (notification .extras .getBoolean (Notification .EXTRA_SHOW_CHRONOMETER , false ));
145
146
out .writeBoolean (showWhen );
146
147
serializeString (out , notification .extras .getString (KEY_INTENT_DATA ));
148
+ out .writeBoolean (notification .extras .getBoolean (SHOW_IN_FOREGROUND , true ));
147
149
}
148
150
149
151
serializeString (out , Build .VERSION .SDK_INT < Build .VERSION_CODES .O ? null : notification .getChannelId ());
@@ -275,7 +277,7 @@ private static Notification.Builder deserializeNotificationCustom(DataInputStrea
275
277
int id = 0 ;
276
278
String title , text , smallIcon , largeIcon , bigText , intentData ;
277
279
long fireTime , repeatInterval ;
278
- boolean usesStopWatch , showWhen ;
280
+ boolean usesStopWatch , showWhen , showInForeground = true ;
279
281
Bundle extras = null ;
280
282
try {
281
283
extras = deserializeParcelable (in );
@@ -296,6 +298,8 @@ private static Notification.Builder deserializeNotificationCustom(DataInputStrea
296
298
usesStopWatch = in .readBoolean ();
297
299
showWhen = in .readBoolean ();
298
300
intentData = deserializeString (in );
301
+ if (version > 0 )
302
+ showInForeground = in .readBoolean ();
299
303
} else {
300
304
title = extras .getString (Notification .EXTRA_TITLE );
301
305
text = extras .getString (Notification .EXTRA_TEXT );
@@ -335,6 +339,7 @@ private static Notification.Builder deserializeNotificationCustom(DataInputStrea
335
339
builder .getExtras ().putLong (KEY_REPEAT_INTERVAL , repeatInterval );
336
340
if (intentData != null )
337
341
builder .getExtras ().putString (KEY_INTENT_DATA , intentData );
342
+ builder .getExtras ().putBoolean (SHOW_IN_FOREGROUND , showInForeground );
338
343
}
339
344
if (title != null )
340
345
builder .setContentTitle (title );
0 commit comments