locked
UAP Windows 10 ExtendedExecutionResult is Denied during Battery Saver Mode RRS feed

  • Question

  • I have a code that works in foreground and background using Extended Execution. I adapted UAP Samples for Extended Execution. However when phone enters Battery Saver Mode then Extended Execution is Denied. Please provide a working solution to let the Windows to continue to execute location tracking in background during Battery Saver Mode.

            private async void BeginExtendedExecution()
            {
                EndExtendedExecution();
                Session = new ExtendedExecutionSession();
                Session.Reason = ExtendedExecutionReason.LocationTracking;
                Session.Description = "Tracking Your Location";
                Session.Revoked += SessionRevoked;
                ExtendedExecutionResult result = await Session.RequestExtensionAsync();

                switch (result)
                {
                    case ExtendedExecutionResult.Allowed:
                        if (G == null) { G = await StartLocationTrackingAsync(); }
                        break;
                    default:
                    case ExtendedExecutionResult.Denied:
                        var msg = new MessageDialog("Extended Denied");
                        await msg.ShowAsync();

                       break;
                }
            }

            private void EndExtendedExecution()
            {
                if (Session != null)
                {
                    Session.Revoked -= SessionRevoked;
                    Session.Dispose();
                    Session = null;
                }
            }

            private async void SessionRevoked(object sender, ExtendedExecutionRevokedEventArgs args)
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                {
                    switch (args.Reason)
                    {
                        case ExtendedExecutionRevokedReason.Resumed:
                            BeginExtendedExecution();
                            break;
                        case ExtendedExecutionRevokedReason.SystemPolicy:
                            BeginExtendedExecution();
                            break;
                    }
                });
            }

    PeaceMan

    Tuesday, September 20, 2016 3:14 AM

Answers

  • Brilliant...you have helped in solving a problem that has been posted in past under UAP but without resolution.

    Few things come up during implementation

    How to invoke battery saver with ARM since the cable provides the power to device.

    How to invoke battery saver with Emulator since the power is supplied by Laptop.

    Is there a way to check in C# that user has finally chosen "Always On" in the battery saver option. 


    PeaceMan

    • Marked as answer by GolfMan Wednesday, September 21, 2016 3:46 AM
    Tuesday, September 20, 2016 5:20 PM

All replies

  • Hi @GilfMan,

    Welcome to the Developing Universal Windows apps forum!

    Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools , and don't forget add tag to your question.

    If you want that your code also run in the Battery Saver mode. then you should add it to the Battery saver settings list.

    You can show the dialog for user like "This app is not able to work correct in  Battery saver mode  then add it to the Battery saver settings list" 

     <TextBlock x:Name="LocationDisabledMessage" FontStyle="Italic"
                      Margin="0,15,0,0" TextWrapping="Wrap" >
              <Run Text="This app is not able to work correct in the Battery Saver mode. Go to " />
                  <Hyperlink NavigateUri="ms-settings:batterysaver-settings">
                      <Run Text="Settings" />
                  </Hyperlink>
              <Run Text=" to add it to the Battery Saver list"/>
      </TextBlock>
    related posts 

     

    Make the community better together

    Tuesday, September 20, 2016 8:52 AM
  • Brilliant...you have helped in solving a problem that has been posted in past under UAP but without resolution.

    Few things come up during implementation

    How to invoke battery saver with ARM since the cable provides the power to device.

    How to invoke battery saver with Emulator since the power is supplied by Laptop.

    Is there a way to check in C# that user has finally chosen "Always On" in the battery saver option. 


    PeaceMan

    • Marked as answer by GolfMan Wednesday, September 21, 2016 3:46 AM
    Tuesday, September 20, 2016 5:20 PM