|
10 | 10 | import androidx.annotation.Nullable; |
11 | 11 | import androidx.annotation.RestrictTo; |
12 | 12 | import androidx.annotation.VisibleForTesting; |
| 13 | +import androidx.core.app.NotificationManagerCompat; |
13 | 14 |
|
14 | 15 | import com.iterable.iterableapi.util.DeviceInfoUtils; |
15 | 16 |
|
@@ -49,7 +50,7 @@ public class IterableApi { |
49 | 50 | private String inboxSessionId; |
50 | 51 | private IterableAuthManager authManager; |
51 | 52 | private HashMap<String, String> deviceAttributes = new HashMap<>(); |
52 | | - private IterableKeychain keychain; |
| 53 | + public IterableKeychain keychain; |
53 | 54 |
|
54 | 55 | void fetchRemoteConfiguration() { |
55 | 56 | apiClient.getRemoteConfiguration(new IterableHelper.IterableActionHandler() { |
@@ -389,14 +390,26 @@ public void onSwitchToBackground() {} |
389 | 390 | }; |
390 | 391 |
|
391 | 392 | 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 | + |
392 | 397 | if (!_firstForegroundHandled) { |
393 | 398 | _firstForegroundHandled = true; |
394 | | - if (sharedInstance.config.autoPushRegistration && sharedInstance.isInitialized()) { |
395 | | - IterableLogger.d(TAG, "Performing automatic push registration"); |
| 399 | + fetchRemoteConfiguration(); |
| 400 | + } |
| 401 | + |
| 402 | + if (sharedInstance.config.autoPushRegistration && sharedInstance.isInitialized() && isNotificationEnabled != systemNotificationEnabled) { |
| 403 | + if (systemNotificationEnabled) { |
396 | 404 | sharedInstance.registerForPush(); |
| 405 | + } else { |
| 406 | + sharedInstance.disablePush(); |
397 | 407 | } |
398 | | - fetchRemoteConfiguration(); |
399 | 408 | } |
| 409 | + |
| 410 | + SharedPreferences.Editor editor = sharedPref.edit(); |
| 411 | + editor.putBoolean(IterableConstants.SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED, systemNotificationEnabled); |
| 412 | + editor.apply(); |
400 | 413 | } |
401 | 414 |
|
402 | 415 | private boolean isInitialized() { |
|
0 commit comments