예제 #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();
            }
        }
예제 #2
0
        private async void PinBatteryTile()
        {
            var deviceId   = DeviceManager.DeviceId;
            var deviceName = DeviceManager.DeviceName;
            var result     = await TilesHelper.PinBatteryTileAsync(deviceId, deviceName);

            if (!result)
            {
                this.UseBatteryLiveTile = false;
                return;
            }

            this.RegisterBatteryTask();

            var batteryPercentage = await DeviceManager.GetBatteryPercentageAsync();

            TilesHelper.UpdateBatteryTile(batteryPercentage);
        }
예제 #3
0
        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);
            });
        }