Android Question Turn on device / Unlock device

plager

Member
Hello community,
apparently, there is difference between turn on device, and unlock device.
This code:
B4X:
Sub Process_Globals
    Dim mPhone As Phone
    Dim mPhoneEvents As PhoneEvents
End Sub

Sub Service_Create
    Dim pID As PhoneId
    mPhoneEvents.InitializeWithPhoneState("PE", pID)
End Sub

Sub PE_ScreenOn(Intent As Intent)
    LogColor("SCREEN ON", Colors.Red)
End Sub

correctly catches status, when I turn device ON. It has status BEFORE unlock the screen, no matter, if biometric, PIN, or pattern. Usually, if I do nothing, device will go to OFF status in 5 seconds.

However, when I unlock the device, there is no other event happening. Unlock device means device to be able to use.
There is NO event in phone library (or I can't find it), when device is really unlocked and ready to use. Can anybody help me with this?

There are three statuses:
- device OFF
- device turned ON
- device UNLOCKED

I can catch device OFF (works nicely):

B4X:
Sub PE_ScreenOff(Intent As Intent)
    LogColor("SCREEN OFF", Colors.Red)
End Sub

I can catch device ON (also works nicely):
B4X:
Sub PE_ScreenOn(Intent As Intent)
    LogColor("SCREEN ON", Colors.Red)
End Sub

But I can't catch device UNLOCKED :(

Please, help me with this.
Thanks.
 
Solution
OK, silly me. There is obviously an event called UserPresent.
So, this piece of code catches screen being unlocked:
B4X:
Sub PE_UserPresent (Intent As Intent)
    Log("You just unlocked a screen.")
End Sub

plager

Member
OK, silly me. There is obviously an event called UserPresent.
So, this piece of code catches screen being unlocked:
B4X:
Sub PE_UserPresent (Intent As Intent)
    Log("You just unlocked a screen.")
End Sub
 
Upvote 0
Solution
Top