I have seen many questions about detecting the dark mode like this one on stack overflow and visited many medium blogs like How to know when you’re using dark mode programmatically and DayNight — Adding a dark theme to your app and in all of them they perform a check like this one:
fun isNightModeEnabled(context: Context): Boolean =
context.resources.configuration.uiMode.and(UI_MODE_NIGHT_MASK) ==
UI_MODE_NIGHT_YES
and this works well in any phone and even the Xiaomi mobiles that run Android One but not on the Xiaomi smartphones that run MIUI.
For Xiaomi devices running MIUI:
context.resources.configuration.uiMode
= 17
and context.resources.configuration.uiMode.and(UI_MODE_NIGHT_MASK)
= 16
Which compared to UI_MODE_NIGHT_YES (32)
always returns false with dark mode enabled or disabled.
Is it really possible to detect that the dark mode has been forced on such devices?