Detect if screen is locked

3,713 views
Skip to first unread message

Matt R

unread,
Dec 30, 2012, 12:07:01 AM12/30/12
to tas...@googlegroups.com
Try the window label variable (%WIN).

Matt

Pent

unread,
Dec 30, 2012, 3:06:37 AM12/30/12
to Tasker
If display goes off, and you have it configured to lock after X
seconds, you could run a task that waits X seconds then sets a %Locked
variable.

Next time the display comes on, you know it's showing the lock screen.

Pent

Andreas Scherbaum

unread,
Dec 30, 2012, 8:11:25 AM12/30/12
to tas...@googlegroups.com
Have a similar problem: want to popup a menu when headset is plugged in. In case the phone is unlocked I also want to include the dialer.
What value should %WIN have if the screen is locked? Having a state %LOCKED or something similar would be helpful.


Regards,
Andreas

On Saturday, December 29, 2012 1:18:16 AM UTC+1, Guillaume Jimenez wrote:
I am trying to start a task when the screen is locked (the user can swipe or type is PIN/password/pattern).
Is there a way to detect this state?

My goal is to unlock the phone with my voice instead of using the PIN code, for instance when my hands are busy (or wearing gloves!).
So I need to detect that the phone is asking for swiping or entering my PIN code.

I cannot find a variable holding the state of the screen (besides on and off), or the app running (is there even a specific app running when asking for PIN?).
Maybe I can detect the lock screen background image or some other indirect way of finding out if the screen is locked.

Another alternative to reach my voice unlock goal would be to require an action from the user. For instance long press on a hardware button (but I did not find this in tasker either).

Thanks!

Pent

unread,
Dec 30, 2012, 10:43:46 AM12/30/12
to Tasker


> Having a state %LOCKED> or something similar would be helpful.

Android doesn't send any signal when the phone is locked.

Pent

Andreas Scherbaum

unread,
Dec 30, 2012, 12:25:29 PM12/30/12
to tas...@googlegroups.com
And there is no way for Tasker to detect this state? :-(
I mean, this could be very helpful to know if the device is locked or not.


Andreas

Richard Davis

unread,
Dec 30, 2012, 1:02:34 PM12/30/12
to tas...@googlegroups.com

It looks like the plug in 'secure settings' has a feature to enable the lock screen. Perhaps use this instead of the phones lock screen.  Something like--

Screen off -----   enable lock screen / %Lock = 1
Screen on ---       if %Lock = 1 then. Disable lock screen / do voice input..

Or something like that any way... just a thought...

Rich...

Andreas Scherbaum

unread,
Dec 30, 2012, 1:29:50 PM12/30/12
to tas...@googlegroups.com
Ok, two profiles:

Profile: Display Locked:
State: Display State Off
Variable Set: %Display_Locked = 1

Profile: Display Unlocked
Event: Display Unlocked
Variable Set: %Display_Locked = 0

This works for me, because my devices are immediately locked when switched off. Might be different if people have a lock delay configured.
Hence it would still be useful if Tasker has his own state.


Andreas

Guillaume Jimenez

unread,
Dec 30, 2012, 6:20:49 PM12/30/12
to tas...@googlegroups.com
Thanks for the tips!

I tried both ideas separately: setting a locked variable and reading the Window Label when the display is locked (which by the way on my phone is 'Verizon Wireless').
The two solutions work well. The task starts when the display turns back on so that's great!

Now, I am getting another problem: The task is supposed to call get voice but
get voice goes on and off almost at the same time (I can hear the sound telling me I can speak and immediately after the sound turning the voice capturing off).
Is it because the phone is locked (maybe voice capturing is not allowed)?
The problem does not occur when the phone is not locked. (for instance if I start the task manually).

Richard Davis

unread,
Dec 30, 2012, 6:35:19 PM12/30/12
to tas...@googlegroups.com

The one thing you could try is turning off the key lock with secure settings. It has been known to cause problems..

Rich...

Guillaume Jimenez

unread,
Dec 30, 2012, 10:26:00 PM12/30/12
to tas...@googlegroups.com
Ok, I can try to unlock the phone for a few seconds and relock it if the password is wrong.
Though it looks like it would be a pretty big security hole.

Richard Davis

unread,
Dec 30, 2012, 10:39:04 PM12/30/12
to tas...@googlegroups.com


> Ok, I can try to unlock the phone for a few seconds and relock it if the password is wrong.
> Though it looks like it would be a pretty big security hole.

Sorry, I meant the key guard.. it most likely is not the problem but it is a easy place to start.. and i am not sure what to try after that.. :(

piotrze

unread,
Jan 4, 2014, 11:17:10 AM1/4/14
to tas...@googlegroups.com, andreas....@gmail.com
W dniu niedziela, 30 grudnia 2012 19:29:50 UTC+1 użytkownik Andreas Scherbaum napisał:
Ok, two profiles:

Profile: Display Locked:
State: Display State Off
Variable Set: %Display_Locked = 1

Profile: Display Unlocked
Event: Display Unlocked
Variable Set: %Display_Locked = 0

This works for me, because my devices are immediately locked when switched off. Might be different if people have a lock delay configured.


If you have clean KitKat, the lock appears after a few seconds (after turning off the screen) and this time is not configurable (or at least I do not know where this can be changed). For having such a problem, I recommend the following solution: https://bitbucket.org/laceous/android-atlockscreen/wiki/Home
 

M@xF@ctor

unread,
Feb 22, 2018, 4:31:34 PM2/22/18
to Tasker
Check Screen Lock Status (532)

A1: Java Function [ Return:kgm Class Or Object:CONTEXT Function:getSystemService
{KeyguardManager} (String) Param:keyguard Param: Param: Param: Param: Param: Param: ]

A2: Java Function [ Return:%Status_Locked Class Or Object:kgm Function:inKeyguardRestrictedInputMode
{boolean} () Param: Param: Param: Param: Param: Param: Param: ]

Variable %Status_Locked will contain true or false

I launch this task on Event -> Variable Set -> %SCREEN

Reply all
Reply to author
Forward
0 new messages