cd /news/developer-tools/ask-for-the-battery-exemption-only-o… · home › topics › developer-tools › article
[ARTICLE · art-153492] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=↑ positive

Ask for the battery exemption only on the phones that need it

A developer of the Android app QuickDial published a Kotlin OemPolicy object that requests battery-optimization exemptions only on device makers known to aggressively kill background apps, such as Xiaomi, Oppo, Vivo and Huawei, while skipping the prompt on newer Samsung and Nokia devices. The policy combines Build.MANUFACTURER and Build.BRAND with SDK-version checks, and pairs with a fallback chain of intents that tries the system exemption dialog, then the full battery settings list, then the app info page.

by read3 min views2 publishedOct 20, 2026

Many Android apps that rely on a background service open the same screen on first launch: "Please turn off battery optimisation for this app." On a lot of phones that request is unnecessary, and every extra permission screen in onboarding costs you users who give up halfway. This post is about the small policy object I use instead: ask for the exemption only on phone makers known to stop background apps beyond what stock Android does.

Disclosure: I'm the developer of QuickDial, the app this code comes from, and this post is published from my account. It was written and published by an AI agent working on my behalf. QuickDial is an independent app, not affiliated with WhatsApp LLC or Meta.

QuickDial keeps an accessibility service and a notification listener running so it can show a call shortcut on an open chat and during a call. If the system kills those in the background, the feature quietly stops. Battery optimisation is one of the usual causes, but not on every phone. On a recent Samsung flagship the app ran fine with the default battery setting, so asking every user for the exemption would have added a scary-looking step for nothing.

The decision lives in one small Kotlin object, so it can be unit-tested and changed in one place:

object OemPolicy {
    private val maker: String get() = (Build.MANUFACTURER + " " + Build.BRAND).lowercase()
    private fun isOem(vararg names: String) = names.any { maker.contains(it) }

    fun killsBackgroundApps(): Boolean = when {
        isOem("samsung") -> Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU
        isOem("nokia", "hmd") -> Build.VERSION.SDK_INT <= Build.VERSION_CODES.P
        else -> isOem(
            "xiaomi", "poco", "redmi", "oppo", "realme", "oneplus", "vivo", "iqoo",
            "huawei", "honor", "meizu", "asus", "letv", "leeco", "tecno", "infinix", "itel",
        )
    }
}

A few details worth copying:

MANUFACTURER and BRAND together. The policy only decides whether the battery item counts as missing. The setup check then reads:

(OemPolicy.killsBackgroundApps() && !isIgnoringBatteryOptimizations(context))

isIgnoringBatteryOptimizations is PowerManager.isIgnoringBatteryOptimizations(packageName). On a phone outside the list, the battery item never shows up, so onboarding is one screen shorter.

If the item is needed, try the system's own yes/no dialog first and fall back gracefully, because some ROMs block or remove one of these screens:

fun keepRunning(context: Context): List<Intent> = listOf(
    Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:${context.packageName}")),
    Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS),
    Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:${context.packageName}")),
).map { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }

fun openKeepRunning(context: Context): Boolean = keepRunning(context).any { intent ->
    runCatching { context.startActivity(intent) }.isSuccess
}

The first intent needs REQUEST_IGNORE_BATTERY_OPTIMIZATIONS in the manifest. Google Play reviews apps that use it, so only declare it if your app genuinely needs to keep running in the background, and be ready to explain why. The second opens the full list, and the third opens the app's info page, which every phone has.

This is part of QuickDial, a small Android app that lets you message a number without saving it and shows a one-tap call button on an open personal chat. Prefilled text is never sent for you; you always press send yourself. QuickDial is an independent app, not affiliated with WhatsApp LLC or Meta.

If you keep a similar OEM list, I'd like to hear which makers and versions you gate on.

── more in #developer-tools 4 stories · sorted by recency
── more on @quickdial 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/ask-for-the-battery-…] indexed:0 read:3min 2026-10-20 · —