Android Question WebSocket Close

Declan

Well-Known Member
Licensed User
Longtime User
I am running an app that uses WebSocket to connect to a server.
If the user closes the app on the Tablet, the server side receives the Disconnect.
However, if the app is running on the Tablet and the user switches the Tablet Off using the Power Switch, the server side does not receive the Disconnect.

I was thinking of using the following code, which works with a "soft" shutdown button in the app.
When the user clicks the Power Switch, I sense the PE_ScreenOff:
B4X:
Sub PE_ScreenOff (Intent As Intent)
   
    Log("ScreenOff")
    Log(Intent.ExtrasToString)

    Dim result As Int
    result = Msgbox2("SWITCH OFF YOUR TABLET?", "Assistant", "SWITCH OFF", "NO", "",LoadBitmap (File.DirAssets, "notification-logo.png"))
    If result = DialogResponse.Positive Then ' Close the WebSocket and Shutdown
        Log("Switch OFF")
        If WebSocket.ws.Connected Then
            If WebSocket.tmrReConnect.Enabled = True Then
                WebSocket.tmrReConnect.Enabled = False
            End If
            Log("Closing WebSocket")
            WebSocket.ws.Close
            Log("Socket State: " & WebSocket.ws.Connected)
        End If
        ToastMessageShow("Shutting Down", True)
        Starter.csu.CallSubPlus(HomePage, "Shutdown", 1000)
    Else
        ' Close message box
    End If
End Sub
However, my problem is that once the screen is off, the user cannot see the MsgBox.
How can I keep the screen alive once the user has pressed the Power Switch?
 

DonManfred

Expert
Licensed User
Longtime User
How can I keep the screen alive once the user has pressed the Power Switch?
You can not capture the press of this hardware button.
 
Upvote 0
Top