I made some modification to be work fine even if you are connected to network but no internet ..
Orginal post here
B4X:
Sub Connected As Boolean
'Requires Phone Library
Dim p As Phone
Dim Response, Error As StringBuilder
Response.Initialize
Error.Initialize
'Ping Google DNS
p.Shell("ping -c 1 8.8.8.8",Null,Response,Error)
If Error.ToString="" And Response.ToString.Contains("Destination Host Unreachable")=False Then
Return True
Else
Return False
End If
End Sub
Orginal post here