I want to programmatically enable or disable the Bedtime Mode from my app. The action must be able to run while the device is in standby mode. Possible options for me are:
- manipulate system settings directly from within the app
- call a service/activity from the app that sets the desired state
- programmatically interact with the quick settings toggle for "Bedtime Mode" to set the desired state
The environment I need my app to work on is Android 14 on Google Pixel Devices. It would be an acceptable solution for me to access secure settings, if needed. The overall goal is later to use Home Assistant to trigger my app (via notification) which then sets the bedtime mode accordingly.
I found little to no documentation about this feature, and ChatGPT/Bard are proposing solutions which introduce dependencies which I can't resolve. Some failed solutions included:
Settings.Secure.getInt(applicationContext.contentResolver, "accessibility_display_daltonizer_enabled")
import androidx.digitalwellbeing.DigitalWellbeingManager
getSystemService(Context.DIGITAL_WELLBEING_SERVICE) as DigitalWellbeingManager
Note: It appears like android Bedtime Mode has had several different names in the past, depending on OS version and device manufacturer. Some related names are "Zen Mode", "Focus Mode" and "Bedtime Mode" as part of digital wellbeing. I am not referring to DnD (Do not Disturb).