Example #1
0
        private async Task OnTimeBatteryLevelBackgroundTaskActivated(IBackgroundTaskInstance backgroundTaskInstance)
        {
            if (!TilesHelper.BatteryTileExists())
            {
                return;
            }

            var applicationsService = new ApplicationsService();

            var errorMessage = await DeviceManager.ConnectAsync(isBackgroundActivity : true);

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                return;
            }

            var percentage = await DeviceManager.GetBatteryPercentageAsync();

            if (percentage > 0)
            {
                TilesHelper.UpdateBatteryTile(percentage);
            }
            else
            {
                TilesHelper.ResetBatteryTile();
            }
        }
Example #2
0
        public override void Initialize()
        {
            this.ApplicationName         = Package.Current.DisplayName;
            this.CustomDate              = DateTimeOffset.Now;
            this.CustomTime              = DateTimeOffset.Now.TimeOfDay;
            this.DeviceName              = DeviceManager.DeviceName;
            this.EnableUserNotifications = BackgroundManager.IsBackgroundTaskRegistered(BackgroundManager.UserNotificationsTaskName);

            var lastSavedBatteryTaskFrequency = SettingsHelper.GetValue(Constants.LastSavedBatteryTaskFrequencySettingKey, (uint)15);

            this.BatteryCheckFrequency = this.AvailableBatteryCheckFrequencies.FirstOrDefault(bf => bf.Minutes == lastSavedBatteryTaskFrequency);

            this.UseBatteryLiveTile = TilesHelper.BatteryTileExists();
        }