Android Question Screen/Phones Locked Status

iCAB

Well-Known Member
Licensed User
Hi Guys

Does anyone know how to check if the phone/screen is locked?

Thanks
iCAB
 

KZero

Active Member
Licensed User
you can detect if phone screen turned off

B4X:
'in a service
Sub Service_Create
    Dim PE As PhoneEvents
    PE.Initialize("PE")
End Sub

Sub PE_ScreenOff(Intent As Intent)
    Log("Screen Off")
End Sub
 

iCAB

Well-Known Member
Licensed User
Thanks KZero,

Here is the code that I added.
The service is starting ok, but the event is not triggered when I lock the phone.

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    
    Dim PhoneId As PhoneId
    Dim PE As PhoneEvents
    
End Sub

Sub Service_Create
    
    PE.InitializeWithPhoneState("PE", PhoneId)
    
    Log("Phone State detected service." )
End Sub

Sub Service_Start (StartingIntent As Intent)
    
    Log("Phone State detected service Started.")
End Sub

Sub Service_Destroy

End Sub


Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    Log("This phone is " & State & ".")
End Sub
I am also requesting the corresponding permission
B4X:
Starter.rp.PERMISSION_READ_PHONE_STATE)


Any ideas?

Thank you
 

KZero

Active Member
Licensed User
Thanks KZero,

Here is the code that I added.
The service is starting ok, but the event is not triggered when I lock the phone.

B4X:
#Region  Service Attributes
    #StartAtBoot: False
   
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
    Dim PhoneId As PhoneId
    Dim PE As PhoneEvents
   
End Sub

Sub Service_Create
   
    PE.InitializeWithPhoneState("PE", PhoneId)
   
    Log("Phone State detected service." )
End Sub

Sub Service_Start (StartingIntent As Intent)
   
    Log("Phone State detected service Started.")
End Sub

Sub Service_Destroy

End Sub


Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    Log("This phone is " & State & ".")
End Sub
I am also requesting the corresponding permission
B4X:
Starter.rp.PERMISSION_READ_PHONE_STATE)


Any ideas?

Thank you
you didn't add the ScreenOff event
B4X:
Sub PE_ScreenOff(Intent As Intent)
    Log("Screen Off")
End Sub
 
Top