Hi,
I am trying to create a mobile app using Godot 4.4, and would like to know how to make the app trigger the mobile ‘sleep mode’ (app doesn’t have to run in background). Also, is there a way to trigger a screen dimming to keep the app running?
The app will have timers running, sort of a stopwatch idea.
Mobile OSs are pretty aggressive about power consumption and sleep. They’re also fairly distrusting about giving apps too much control, for a variety of reasons. Screen dimming is typically under OS control as well.
A couple of things that might be of use:
iOS and Android both have ways of scheduling “local notifications” where the OS wakes the app (and the phone if necessary, assuming it hasn’t been powered off…) and delivers a specified message. These can be sent from an app to itself in the future, and can be made silent so the user doesn’t see/hear them. You should be able to do timer stuff with that.
At present the only way I know to keep an iOS device (and the app on it) awake reliably is to play an audio stream. As long as the audio stream is playing, the app gets treated as a music player and is kept alive/awake. You can do this with a silent looped audio file if you like, though getting that past the app store approval process is left as an exercise to the reader.
Thanks for that, I will explore the silent notifications for future development of the app, as it is part of my product roadmap.
At the moment, the app stays always on display which is energy consumming. I have seen a setting about turning off Always on Display for Android export, but it doesn’t seem to be working. I must be doing something wrong. Any ideas?
I know there are ways of spawning background tasks (though keeping them alive without doing something awful like polling location services can be an issue…) but I’m not sure if you have access to them via Godot.
Hi, it works, perfect!
Do you know if there is a way to have the screen dimming instead of full stop?
[Edit]
It works well, however, I am trying to change this settings in runtime, to keep it on screen on some functionalities, and it doesn’t work
I am using the following
var keep_alive: bool
# keep_alive will be either true or false, and changed in the script
ProjectSettings.set_setting("display/window/energy_saving/keep_screen_on", keep_alive)