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(); } }
private async void UpdateBatteryPercentage(int?newPercentage = null) { await DispatcherHelper.RunAsync(async() => { if (!newPercentage.HasValue) { newPercentage = await DeviceManager.GetBatteryPercentageAsync(); } if (newPercentage > 0) { TilesHelper.UpdateBatteryTile(newPercentage); } else { TilesHelper.ResetBatteryTile(); } var oldPercentage = this.BatteryPercentage; this.BatteryPercentage = newPercentage.Value; this.BatteryLevel = BatteryHelper.Parse(newPercentage.Value); }); }