Skip to content

Commit 9022279

Browse files
committed
[MOB-9446] Logic fix
1 parent 33f69c3 commit 9022279

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,22 +390,24 @@ public void onSwitchToBackground() {}
390390
};
391391

392392
private void onForeground() {
393-
boolean systemNotificationEnabled = NotificationManagerCompat.from(_applicationContext).areNotificationsEnabled();
394-
SharedPreferences sharedPref = sharedInstance.getMainActivityContext().getSharedPreferences(IterableConstants.SHARED_PREFS_FILE, Context.MODE_PRIVATE);
395-
boolean isNotificationEnabled = sharedPref.getBoolean(IterableConstants.SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED, false);
396-
397393
if (!_firstForegroundHandled) {
398394
_firstForegroundHandled = true;
399395
fetchRemoteConfiguration();
400-
}
401396

402-
if (sharedInstance.config.autoPushRegistration && sharedInstance.isInitialized() && isNotificationEnabled != systemNotificationEnabled) {
403-
if (systemNotificationEnabled) {
404-
sharedInstance.registerForPush();
405-
} else {
406-
sharedInstance.disablePush();
407-
}
408-
}
397+
if (sharedInstance.config.autoPushRegistration && sharedInstance.isInitialized()) {
398+
sharedInstance.registerForPush();
399+
}
400+
}
401+
402+
boolean systemNotificationEnabled = NotificationManagerCompat.from(_applicationContext).areNotificationsEnabled();
403+
SharedPreferences sharedPref = sharedInstance.getMainActivityContext().getSharedPreferences(IterableConstants.SHARED_PREFS_FILE, Context.MODE_PRIVATE);
404+
boolean isNotificationEnabled = sharedPref.getBoolean(IterableConstants.SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED, false);
405+
406+
if (sharedInstance.isInitialized() && isNotificationEnabled != systemNotificationEnabled) {
407+
if (!systemNotificationEnabled) {
408+
sharedInstance.disablePush();
409+
}
410+
}
409411

410412
SharedPreferences.Editor editor = sharedPref.edit();
411413
editor.putBoolean(IterableConstants.SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED, systemNotificationEnabled);

0 commit comments

Comments
 (0)