4
votes

I've been looking for a way to detect programmatically if a user has enabled/disabled the Adaptive Battery setting on their device, but have been unable to find anything.

I know many settings can be checked, such as the user ignoring battery optimizations: ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS

However, I have only found the ability to check which bucket your app currently belongs to: getAppStandbyBucket()

Is there a way to determine if the user has turned off Adaptive Battery, similar to the Battery Optimization Setting?

1

1 Answers

0
votes

I don't know, why it's missing in SDK, but you can found this settings key in Android source here:

    /**
     * Whether or not adaptive battery feature is enabled by user. Platform will turn on this
     * feature if both this flag and {@link #APP_STANDBY_ENABLED} is on.
     * Type: int (0 for false, 1 for true)
     * Default: 1
     * @hide
     * @see #APP_STANDBY_ENABLED
     */
    @Readable
    public static final String ADAPTIVE_BATTERY_MANAGEMENT_ENABLED =
            "adaptive_battery_management_enabled";

So to get current status use this function (tested):

fun isAdaptiveBatteryEnabled(ctx: Context): Boolean {
    val intValue = Settings.Global.getInt(
        ctx.contentResolver,
        "adaptive_battery_management_enabled",
        -1
    )
    return intValue == 1
}