@@ -80,7 +80,7 @@ private static class OneSignalNotificationBuilder {
8080 boolean hasLargeIcon ;
8181 }
8282
83- static void setStatics (Context inContext ) {
83+ private static void setStatics (Context inContext ) {
8484 currentContext = inContext ;
8585 packageName = currentContext .getPackageName ();
8686 contextResources = currentContext .getResources ();
@@ -313,8 +313,18 @@ private static void showNotification(NotificationGenerationJob notifJob) {
313313 OneSignal .Log (OneSignal .LOG_LEVEL .ERROR , "Could not set background notification image!" , t );
314314 }
315315
316- if (notifJob .overrideSettings != null && notifJob .overrideSettings .extender != null )
316+ if (notifJob .overrideSettings != null && notifJob .overrideSettings .extender != null ) {
317+ notifJob .orgFlags = notifBuilder .mNotification .flags ;
318+ notifJob .orgSound = notifBuilder .mNotification .sound ;
317319 notifBuilder .extend (notifJob .overrideSettings .extender );
320+
321+ notifJob .overriddenBodyFromExtender = notifBuilder .mContentText ;
322+ notifJob .overriddenTitleFromExtender = notifBuilder .mContentTitle ;
323+ if (!notifJob .restoring ) {
324+ notifJob .overriddenFlags = notifBuilder .mNotification .flags ;
325+ notifJob .overriddenSound = notifBuilder .mNotification .sound ;
326+ }
327+ }
318328
319329 // Keeps notification from playing sound + vibrating again
320330 if (notifJob .restoring )
@@ -329,7 +339,8 @@ private static void showNotification(NotificationGenerationJob notifJob) {
329339 notifBuilder .setDeleteIntent (deleteIntent );
330340 notifBuilder .setGroup (group );
331341
332- notification = notifBuilder .build ();
342+ notification = createSingleNotificationBeforeSummaryBuilder (notifJob , notifBuilder );
343+
333344 createSummaryNotification (notifJob , oneSignalNotificationBuilder );
334345 }
335346 else {
@@ -351,6 +362,28 @@ private static void showNotification(NotificationGenerationJob notifJob) {
351362 NotificationManagerCompat .from (currentContext ).notify (notificationId , notification );
352363 }
353364 }
365+
366+ // Removes custom sound set from the extender from non-summary notification before building it.
367+ // This prevents the sound from playing twice or both the default sound + a custom one.
368+ private static Notification createSingleNotificationBeforeSummaryBuilder (NotificationGenerationJob notifJob , NotificationCompat .Builder notifBuilder ) {
369+ // Includes Android 4.3 through 6.0.1. Android 7.1 handles this correctly without this.
370+ // Android 4.2 and older just post the summary only.
371+ boolean singleNotifWorkArounds = Build .VERSION .SDK_INT > Build .VERSION_CODES .JELLY_BEAN_MR1 && Build .VERSION .SDK_INT <Build .VERSION_CODES .N && !notifJob .restoring ;
372+
373+ if (singleNotifWorkArounds ) {
374+ if (notifJob .overriddenSound != null && !notifJob .overriddenSound .equals (notifJob .orgSound ))
375+ notifBuilder .setSound (null );
376+ }
377+
378+ Notification notification = notifBuilder .build ();
379+
380+
381+ if (singleNotifWorkArounds ) {
382+ notifBuilder .setSound (notifJob .overriddenSound );
383+ }
384+
385+ return notification ;
386+ }
354387
355388 // Xiaomi requires the following to show a custom notification icons.
356389 // Without this MIUI 8 will only show the app icon on the left.
@@ -382,7 +415,7 @@ static void updateSummaryNotification(NotificationGenerationJob notifJob) {
382415 }
383416
384417 // This summary notification will be visible instead of the normal one on pre-Android 7.0 devices.
385- static void createSummaryNotification (NotificationGenerationJob notifJob , OneSignalNotificationBuilder notifBuilder ) {
418+ private static void createSummaryNotification (NotificationGenerationJob notifJob , OneSignalNotificationBuilder notifBuilder ) {
386419 boolean updateSummary = notifJob .restoring ;
387420 JSONObject gcmBundle = notifJob .jsonPayload ;
388421
@@ -493,6 +526,13 @@ static void createSummaryNotification(NotificationGenerationJob notifJob, OneSig
493526 NotificationCompat .Builder summaryBuilder = getBaseOneSignalNotificationBuilder (notifJob ).compatBuilder ;
494527 if (updateSummary )
495528 removeNotifyOptions (summaryBuilder );
529+ else {
530+ if (notifJob .overriddenSound != null )
531+ summaryBuilder .setSound (notifJob .overriddenSound );
532+
533+ if (notifJob .overriddenFlags != null )
534+ summaryBuilder .setDefaults (notifJob .overriddenFlags );
535+ }
496536
497537 // The summary is designed to fit all notifications.
498538 // Default small and large icons are used instead of the payload options to enforce this.
@@ -514,14 +554,18 @@ static void createSummaryNotification(NotificationGenerationJob notifJob, OneSig
514554
515555 // Add the latest notification to the summary
516556 if (!updateSummary ) {
517- String line1Title = gcmBundle .optString ("title" , null );
557+ String line1Title = null ;
558+
559+ if (notifJob .getTitle () != null )
560+ line1Title = notifJob .getTitle ().toString ();
518561
519562 if (line1Title == null )
520563 line1Title = "" ;
521564 else
522565 line1Title += " " ;
523-
524- String message = gcmBundle .optString ("alert" );
566+
567+ String message = notifJob .getBody ().toString ();
568+
525569 SpannableString spannableString = new SpannableString (line1Title + message );
526570 if (line1Title .length () > 0 )
527571 spannableString .setSpan (new StyleSpan (android .graphics .Typeface .BOLD ), 0 , line1Title .length (), 0 );
0 commit comments