/// <summary> /// Installs synchronization using legacy Android features (i.e. alarms). /// </summary> private static void ConfigureSyncLegacy(Context applicationContext, bool enabled) { Log.Debug("Configuring legacy synchronization, enabled: {0}", enabled); try { var broadcastIntent = new Intent(applicationContext, typeof(DataSyncReceiver)); var pendingIntent = PendingIntent.GetBroadcast(applicationContext, DataSyncPendingIntentId, broadcastIntent, PendingIntentFlags.UpdateCurrent); AlarmManager manager = (AlarmManager)applicationContext.GetSystemService(Context.AlarmService); manager.Cancel(pendingIntent); if (enabled) { if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) { manager.SetWindow( AlarmType.Rtc, //Deadline expressed in milliseconds from Unix epoch, does not wake up device SyncManager.NextUploadOpportunity.ToUnixEpochMilliseconds(), (long)((SyncManager.MaxSynchronizationInterval - SyncManager.MinSynchronizationInterval).TotalMilliseconds), pendingIntent); Log.Debug("Scheduled alarm on window from {0} to {1}", SyncManager.NextUploadOpportunity, SyncManager.NextUploadDeadline); } else { manager.Set( AlarmType.Rtc, //Deadline expressed in milliseconds from Unix epoch, does not wake up device SyncManager.NextUploadOpportunity.ToUnixEpochMilliseconds(), pendingIntent); Log.Debug("Scheduled alarm at {0}", SyncManager.NextUploadOpportunity); } } } catch (Exception ex) { Log.Error(ex, "Failed to setup synchronization on alarm manager"); } }