@@ -82,12 +82,26 @@ class GenerateNotification {
82
82
private static Resources contextResources = null ;
83
83
private static Context currentContext = null ;
84
84
private static String packageName = null ;
85
+ private static Integer groupAlertBehavior = null ;
85
86
86
87
private static class OneSignalNotificationBuilder {
87
88
NotificationCompat .Builder compatBuilder ;
88
89
boolean hasLargeIcon ;
89
90
}
90
91
92
+ // NotificationCompat unfortunately doesn't correctly support some features
93
+ // such as sounds and heads-up notifications with GROUP_ALERT_CHILDREN on
94
+ // Android 6.0 and older.
95
+ // This includes:
96
+ // Android 6.0 - No Sound or heads-up
97
+ // Android 5.0 - Sound, but no heads-up
98
+ private static void initGroupAlertBehavior () {
99
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N )
100
+ groupAlertBehavior = NotificationCompat .GROUP_ALERT_CHILDREN ;
101
+ else
102
+ groupAlertBehavior = NotificationCompat .GROUP_ALERT_SUMMARY ;
103
+ }
104
+
91
105
private static void setStatics (Context inContext ) {
92
106
currentContext = inContext ;
93
107
packageName = currentContext .getPackageName ();
@@ -100,6 +114,8 @@ static boolean displayNotification(OSNotificationGenerationJob notificationJob)
100
114
101
115
isRunningOnMainThreadCheck ();
102
116
117
+ initGroupAlertBehavior ();
118
+
103
119
return showNotification (notificationJob );
104
120
}
105
121
@@ -385,7 +401,7 @@ private static void createGenericPendingIntentsForGroup(
385
401
notifBuilder .setGroup (group );
386
402
387
403
try {
388
- notifBuilder .setGroupAlertBehavior (NotificationCompat . GROUP_ALERT_SUMMARY );
404
+ notifBuilder .setGroupAlertBehavior (groupAlertBehavior );
389
405
} catch (Throwable t ) {
390
406
//do nothing in this case...Android support lib 26 isn't in the project
391
407
}
@@ -612,7 +628,7 @@ private static void createSummaryNotification(OSNotificationGenerationJob notifi
612
628
.setGroupSummary (true );
613
629
614
630
try {
615
- summaryBuilder .setGroupAlertBehavior (NotificationCompat . GROUP_ALERT_SUMMARY );
631
+ summaryBuilder .setGroupAlertBehavior (groupAlertBehavior );
616
632
}
617
633
catch (Throwable t ) {
618
634
//do nothing in this case...Android support lib 26 isn't in the project
@@ -674,7 +690,7 @@ private static void createSummaryNotification(OSNotificationGenerationJob notifi
674
690
.setGroupSummary (true );
675
691
676
692
try {
677
- summaryBuilder .setGroupAlertBehavior (NotificationCompat . GROUP_ALERT_SUMMARY );
693
+ summaryBuilder .setGroupAlertBehavior (groupAlertBehavior );
678
694
}
679
695
catch (Throwable t ) {
680
696
//do nothing in this case...Android support lib 26 isn't in the project
@@ -730,7 +746,7 @@ private static void createGrouplessSummaryNotification(
730
746
.setGroupSummary (true );
731
747
732
748
try {
733
- summaryBuilder .setGroupAlertBehavior (NotificationCompat . GROUP_ALERT_SUMMARY );
749
+ summaryBuilder .setGroupAlertBehavior (groupAlertBehavior );
734
750
}
735
751
catch (Throwable t ) {
736
752
// Do nothing in this case... Android support lib 26 isn't in the project
0 commit comments