#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
Starter.rp.PERMISSION_READ_PHONE_STATE)
you didn't add the ScreenOff eventThanks KZero,
Here is the code that I added.
The service is starting ok, but the event is not triggered when I lock the phone.
I am also requesting the corresponding permissionB4X:#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
B4X:Starter.rp.PERMISSION_READ_PHONE_STATE)
Any ideas?
Thank you
Sub PE_ScreenOff(Intent As Intent)
Log("Screen Off")
End Sub