Check if the screen is in idle / sleep mode (screen off)

With this extension you can check if a device is in sleep / idle mode (screen off).

de.bodymindpower.IdleMode.aix (4.9 KB)

Example blocks:

16 Likes

Thank you.

2 Likes

Hello Anke,
I had the chance to try this extension, thank you, it is very good, but unfortunately it is able to detect if the device is just locked/unlocked. If the device is locked with the screen active, it returns true. By logcat, I got this:

Device unlocked --> IdleMode.IsScreenOff = False
Device locked, screen OFF --> IdleMode.IsScreenOff = True
Device locked, screen ON --> IdleMode.IsScreenOff = True

Actually, I am in need to tell apart the last two cases.
Would you be so kind as to implement also an extension to check if the device screen is on of off, please?
Thanks anyway in advance.

Yes, the extension only checks whether the screen (of the app) is off, not whether the device is in idle mode. (I have now adjusted the topic.)

Once the app has been moved to the background, it no longer has permission to query the device's state directly without using a foreground service.

It is exactly what I did: I created an app using Melon Notification and Itoo extensions to implement a foreground service running a timer clock in background and I exploited it to monitor the value returned by your extension, recording it in a logcat file by debug messages.
Here below the AIA project file of my app:

WorkTimeNotifyService_DEBUG.aia (283.6 KB)

Here below the logcat file, where I filtered debug messages only (on each line, I reported on the right the actual status of the device):

03-08 21:32:46.593 30319 30319 I Notifier: DEBUG: IdleMode.IsScreenOff = FALSE ---> Device unlocked
03-08 21:32:51.631 30319 30319 I Notifier: DEBUG: IdleMode.IsScreenOff = FALSE ---> Device unlocked
03-08 21:32:56.649 30319 30319 I Notifier: DEBUG: IdleMode.IsScreenOff = FALSE ---> Device unlocked
03-08 21:32:59.296 18275 2501 I NearbySharing: Screen is locked
03-08 21:33:01.658 30319 30319 I Notifier: DEBUG: IdleMode.IsScreenOff = TRUE ---> Device locked, screen off
03-08 21:33:06.671 30319 30319 I Notifier: DEBUG: IdleMode.IsScreenOff = TRUE ---> Device locked, screen off
03-08 21:33:11.691 30319 30319 I Notifier: DEBUG: IdleMode.IsScreenOff = TRUE ---> Device locked, screen on
03-08 21:33:14.314 31115 31115 I Notifier: DEBUG: Device now LOCKED with screen ON. ---> Here I pressed the button Log Debug in the notification...
03-08 21:33:16.705 30319 30319 I Notifier: DEBUG: IdleMode.IsScreenOff = TRUE ---> Device locked, screen on
03-08 21:33:18.900 18275 30940 I NearbySharing: Screen is unlocked
03-08 21:33:21.745 30319 30319 I Notifier: DEBUG: IdleMode.IsScreenOff = FALSE ---> Device unlocked
03-08 21:33:26.766 30319 30319 I Notifier: DEBUG: IdleMode.IsScreenOff = FALSE ---> Device unlocked
03-08 21:33:28.704 31115 31115 I Notifier: DEBUG: IdleMode.IsScreenOff = FALSE ---> Device unlocked

Having the device locked, my problem is related to those two statuses that can't be told apart: when the screen is on and when the screen is off.
Do you think it is possible to modify your extension or build a new one to detect the screen status also?
Thanks anyway in advance.