Determining screen lock or not

rabiuls

Member
Licensed User
Longtime User
Hello,

Is it possible to detect whether screen is locked or not? I have seen the "UserPresent" of phone library. Is there any other method?

Thanks a lot.
 

rabiuls

Member
Licensed User
Longtime User
I would like to know
Well, OK. Select the Reflection library. The sub bellow will set a variable - 'DeviceLocked' to either 0 or 1:

Sub CheckLock
Dim r As Reflector
Dim isLock As Boolean
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "keyguard", "java.lang.String")
isLock = r.RunMethod("inKeyguardRestrictedInputMode")

If isLock = False Then
DeviceLocked = 0
Else
DeviceLocked = 1
End If
End Sub
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Thank you.

Don't take this the wrong way, I am just trying to teach you how to program faster/easier

B4X:
Sub CheckLock as boolean

Dim r As Reflector

r.Target = r.GetContext

r.Target = r.RunMethod2("getSystemService", "keyguard", "java.lang.String")

return  r.RunMethod("inKeyguardRestrictedInputMode")
end sub
 
Upvote 0

rabiuls

Member
Licensed User
Longtime User
Thank you.

Don't take this the wrong way, I am just trying to teach you how to program faster/easier

B4X:
Sub CheckLock as boolean

Dim r As Reflector

r.Target = r.GetContext

r.Target = r.RunMethod2("getSystemService", "keyguard", "java.lang.String")

return  r.RunMethod("inKeyguardRestrictedInputMode")
end sub

Indeed it's better :sign0142:. Thank you very much.
 
Upvote 0
Top