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.