Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Heads-Up Displaying Previous Notification When Grouped on some devices #1578

Merged
merged 2 commits into from
May 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,26 @@ class GenerateNotification {
private static Resources contextResources = null;
private static Context currentContext = null;
private static String packageName = null;
private static Integer groupAlertBehavior = null;

private static class OneSignalNotificationBuilder {
NotificationCompat.Builder compatBuilder;
boolean hasLargeIcon;
}

// NotificationCompat unfortunately doesn't correctly support some features
// such as sounds and heads-up notifications with GROUP_ALERT_CHILDREN on
// Android 6.0 and older.
// This includes:
// Android 6.0 - No Sound or heads-up
// Android 5.0 - Sound, but no heads-up
private static void initGroupAlertBehavior() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
groupAlertBehavior = NotificationCompat.GROUP_ALERT_CHILDREN;
else
groupAlertBehavior = NotificationCompat.GROUP_ALERT_SUMMARY;
}

private static void setStatics(Context inContext) {
currentContext = inContext;
packageName = currentContext.getPackageName();
Expand All @@ -100,6 +114,8 @@ static boolean displayNotification(OSNotificationGenerationJob notificationJob)

isRunningOnMainThreadCheck();

initGroupAlertBehavior();

return showNotification(notificationJob);
}

Expand Down Expand Up @@ -385,7 +401,7 @@ private static void createGenericPendingIntentsForGroup(
notifBuilder.setGroup(group);

try {
notifBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
notifBuilder.setGroupAlertBehavior(groupAlertBehavior);
} catch (Throwable t) {
//do nothing in this case...Android support lib 26 isn't in the project
}
Expand Down Expand Up @@ -612,7 +628,7 @@ private static void createSummaryNotification(OSNotificationGenerationJob notifi
.setGroupSummary(true);

try {
summaryBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
summaryBuilder.setGroupAlertBehavior(groupAlertBehavior);
}
catch (Throwable t) {
//do nothing in this case...Android support lib 26 isn't in the project
Expand Down Expand Up @@ -674,7 +690,7 @@ private static void createSummaryNotification(OSNotificationGenerationJob notifi
.setGroupSummary(true);

try {
summaryBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
summaryBuilder.setGroupAlertBehavior(groupAlertBehavior);
}
catch (Throwable t) {
//do nothing in this case...Android support lib 26 isn't in the project
Expand Down Expand Up @@ -730,7 +746,7 @@ private static void createGrouplessSummaryNotification(
.setGroupSummary(true);

try {
summaryBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
summaryBuilder.setGroupAlertBehavior(groupAlertBehavior);
}
catch (Throwable t) {
// Do nothing in this case... Android support lib 26 isn't in the project
Expand Down