how to make screen always awake in lua corona? - android

I use Corona for my game, but when I build into my Android smartphone there is a problem that the screen does not stay on (goes to sleep). My question is how to make the screen stay on having to interact with screen?

You can use system.setIdleTimer() to control the idle timer.
Controls whether the idle timer is enabled. If set to true, the timer will be active (default) or inactive if false. When active, the idle timer dims the screen and eventually puts the device to sleep when no user activity occurs (e.g. screen touches).
Example:
system.setIdleTimer(false) -- Screen does not turn off automatically
system.setIdleTimer(true) -- Screen turns off automatically

Related

Simulate an activity to postpone screen turn off

Each time an user touches screen, a timeout counter for turning screen off is reset.
How can I simulate an activity to reset such timeout counter programmatically, to postpone screen turning off?
I am not looking for keeping screen on permanently.
I am experiencing screen off issue when user is requested to use a fingerprint scanner and I want to reset such timeout counter each time when user's fingerprint is not recognized or any fingerprint sensor activity is recorded.
The solution you are looking for is already there in the Android documentation.
It is called Wake Lock. Keep the screen on programmatically using:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
The advantage of setting the flag programmatically in your activity is that it gives you the option of programmatically clearing the flag later and thereby allowing the screen to turn off. If you want to explicitly clear the flag and thereby allow the screen to turn off again, use clearFlags() like so:
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

How to show the screensaver on android?

I already created a bouncing object as an application but I want to make it to be a screensaver.
After 15 seconds inactivity device instead of sleep, the screen shows the screensaver(bouncing object) and quit to the previous screen when the screen is touched.
For the touch action, I currently use onUserInteraction() and it works fine.
I want the screen to show after the device has been in an inactivity period for a while.
*not the DayDream one because DayDream works only when the phone is charged or docked

WakeLock.release() switches off screen even if the user was interacting with the app

My app wakes the phone from standby and turns on the screen (SCREEN_BRIGHT_WAKE_LOCK). I can't use the WindowManager-flags approach, as my app may already be running in the background.
The problem is that once the user dismisses my app and the WakeLock is released, the screen turns off immediately, even if the user was interacting with the app (or the homescreen, which briefly shows while the app is being closed).
Would using the ON_AFTER_RELEASE-flag help?
Yes, you want to use the ON_AFTER_RELEASE flag.
When this wake lock is released, poke the user activity timer so the screen stays on for a little longer.

Does Android have two different sleep modes

When the user presses on the Power button to turn off the screen, at some point Android goes into sleep mode shutting down the CPU. It isn't clear whether this happens immediately or after a period of time. Does the CPU stay fully or partially awake for a duration and then go into a complete sleep mode?
When the user presses the power button, Android goes into screen off mode. Some time after this, the device will go into sleep mode if nothing is kept awake using a Wakelock. The duration of this period is uncertain. See here for more:
https://stackoverflow.com/a/5120225/1369222

Is it possible to get a device to wake up from sleep (screen dark) by detecting a touch to the screen?

I want to get an android device to wake up from sleep or however the state in which the phone gets after a certain amount of inactivity when the screen goes dark, by detecting a touch to the screen instead of clicking on any button.
In the documentation the only thing I have found is the FLAG_TOUCHABLE_WHEN_WAKING flag in WindowManager.LayoutParams and it says:
Window flag: When set, if the device is asleep when the touch screen
is pressed, you will receive this
first touch event. Usually the first
touch event is consumed by the system
since the user can not see what they
are pressing on.
I thought that meant that if the device's screen is turned off and that flag is set for an Activity then it will wake up to the touch (which is what I want it to do). Am I misunderstanding the purpose of this flag? Are there additional implementation details I'm ignoring? Is there some other way?
Am I misunderstanding the purpose of this flag?
AFAIK, yes. There is a slice of time between when the screen turns off and when the device falls asleep. During this time, if the user touches the screen someplace where the window has this flag, the screen turns on again and the inactivity timer is reset.
I can find no other use of this flag in the Android source code.
Is there some other way?
No. If the device is asleep, touch screen events are not registered.

Categories

Resources