Android Question PROXIMITY_SCREEN_OFF_WAKE_LOCK

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello @Erel . I need to use to lock screen when user touches it with his face trying to use the phone (my app does voip phone calls), avoiding mistaken commands. Today I did a workaround creating a full screen activity and then putting a full screen panel consuming the touches (with a 200 alpha and colors.black , with an empty panel_click event in order to consume undesired touches when the proximity value is 0...). But if any other app puts a notification or something else in a layer over this panel I still could have mistaken touches (besides in other app, but it is still a mistaken touch from user)... that's it.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Put in starter service:
B4X:
Sub Process_Globals
   Private ProximityWakeLock As JavaObject
End Sub

Sub Service_Create
   If ProximityWakeLock.IsInitialized = False Then
       Dim ctxt As JavaObject
       ProximityWakeLock = ctxt.InitializeContext.RunMethodJO("getSystemService", Array("power")) _
           .RunMethod("newWakeLock", Array(32, "proximity"))
       ProximityWakeLock.RunMethod("acquire", Null)
       'release code:
       'ProximityWakeLock.RunMethod("release", Null)
   End If
End Sub

Manifest editor:
B4X:
AddPermission(android.permission.WAKE_LOCK)
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Put in starter service:
B4X:
Sub Process_Globals
   Private ProximityWakeLock As JavaObject
End Sub

Sub Service_Create
   If ProximityWakeLock.IsInitialized = False Then
       Dim ctxt As JavaObject
       ProximityWakeLock = ctxt.InitializeContext.RunMethodJO("getSystemService", Array("power")) _
           .RunMethod("newWakeLock", Array(32, "proximity"))
       ProximityWakeLock.RunMethod("acquire", Null)
       'release code:
       'ProximityWakeLock.RunMethod("release", Null)
   End If
End Sub

Manifest editor:
B4X:
AddPermission(android.permission.WAKE_LOCK)

Thanks @Erel ... a question:
- If the device has no proximity sensor... will raise an error?
And... How to know if there is or not proximity sensor?
 
Upvote 0
Top