Android Question Lock Phone On Incoming Call

sktanmoy

Active Member
Licensed User
Longtime User
Fact: When I get a call and phone remains in my pocket, sometimes (basically when I walk), call is automatically picked up. Actually screen is too sensitive and jeans are tight enough to touch while walking

I need: I want to lock the screen when phone will remain in pocket (can detect using proximity sensor) and have a call (can detect using phone event listener)

What I did: I created an app which is perfectly detecting proximity, incoming call and lock screen using device administrator library.

What's happening: Locking is always working except when using in incoming call listener.

Any idea if (and how) I can accomplish my task in this situation.
 

sktanmoy

Active Member
Licensed User
Longtime User
B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

Sub Process_Globals
    Dim PE As PhoneEvents
End Sub
Sub Service_Create
    PE.Initialize("Watch")
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy
    PE.StopListening
End Sub

Sub Watch_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    Sleep(1000)
    ToastMessageShow(IncomingNumber, False)
    StartActivity(Main)
End Sub

Sub Sleep(ms As Long)
Dim now As Long
   If ms > 1000 Then ms =1000   'avoid application not responding error
   now=DateTime.now
   Do Until (DateTime.now>now+ms)
     DoEvents
   Loop
End Sub



Here is my service class. Cannot understand how to use Service.StartForeground here.
 
Upvote 0
Top