How to set ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS on/off within the Xamarin.

Anonymous
2022-06-16T22:39:46.067+00:00

I am trying to achieve ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS on/off within the app. So in a specific activity, it should be on and other off. I could achieve to request the permission and PowerManager.isIgnoringBatteryOptimizations() returning true when I check the app settings is also not optimized

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,371 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 78,671 Reputation points Microsoft Vendor
    2022-06-17T05:35:06.177+00:00

    Hello,​

    You can create a dependence service to invoke code to turn on/off BATTERY_OPTIMIZATION.
    Then use intent.SetAction(Android.Provider.Settings.ActionRequestIgnoreBatteryOptimizations); to turn it on. Use intent.SetAction(Android.Provider.Settings.ActionIgnoreBatteryOptimizationSettings); to turn it off.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.