Used to manage battery optimization:
- Identifies the battery optimization mode for the current application.
- Prompts the user to disable battery optimization for a given application on the device.
This function can be used to tell the operating system to stop preventing the application from running in the background.
// If battery optimization is enabled,
// prompt the user to disable it.
IF SysBatteryOptimBackground() = sboOptimized THEN
SysBatteryOptimBackground(sboRequestDisable)
END
Syntax
Identifying the battery optimization mode for the current application Hide the details
<Result> = SysBatteryOptimBackground()
<Result>: Integer constant
Battery optimization status for the application:
| |
sboNotOptimized | Battery optimization is not enabled for the application. |
sboOptimized | Battery optimization is enabled for the application. |
Changing the battery optimization mode for the current application Hide the details
SysBatteryOptimBackground(<Mode>)
<Mode>: Integer constant
Function call mode: | |
sboRequestDisable | Shows a system message asking the user to disable battery optimization for a given application. If battery optimization is disabled, there is no action. |
sboSystemSettings | Opens the settings window containing the list of applications for which battery optimization disabled. |
Remarks
Google and disabling battery optimization
Google does not recommend disabling battery optimization. Most applications should not use this option. It should only be used for special cases where you need to keep full control of the application execution in the background.
Caution: On some phones, the list of non-optimized/optimized applications is not updated unless you restart the phone. This behavior has been defined by Google. However, the request to disable battery optimization does take effect: the Android settings page is the only page that may not be up to date (this can cause problems when re-enabling battery optimization).
Required permissions
The call to this function modifies the permissions required by the application.
Required permission: REQUEST_IGNORE_BATTERY_OPTIMIZATIONS: Allows the application to ask the user to disable battery optimization.
Caution: If you use this permission without good reason, Google may remove your application from the Play Store.
Requirement
SysBatteryOptimBackground is available only for devices running Android 6.0 or later (API level 23)..
A fatal error occurs if the function is used with an earlier system version.
To determine the version of Android the application is running on, use
SysAndroidVersion.
Component: wd280android.aar