Android Question Unable to access Internet from a Background service

palmzac

Active Member
Licensed User
Longtime User
Hi,

I have a simple background service to download data from internet. Everything is OK before Android 7.1 .

This is my routine for network available checking. It always return FALSE on Android 7.1.x & Android 8.

Would you give me a sample code for internet connection wake-up ? Thanks !

<code>
Sub CheckNet As Boolean

' This sub will determine the WiFi and network connection.

Dim Server As ServerSocket
Dim WiFi_IP As String
Dim Network_IP As String
Dim OK As Boolean = False

Server.Initialize(0,"")
Network_IP = Server.GetMyIP
WiFi_IP = Server.GetMyWifiIP
Server.Close

If WiFi_IP = "127.0.0.1" And Network_IP = "127.0.0.1" Then
OK = False
Else
Log("IPs : " & WiFi_IP & ", " & Network_IP )

Dim p As Phone
Dim Response, Error As StringBuilder
Response.Initialize
Error.Initialize
'Ping Google DNS - if you can't reach this you are in serious trouble!
p.Shell("ping -c 1 8.8.8.8",Null,Response,Error)
Log("======= Response ========")
Log(Response)
Log("======= Error ===========")
Log(Error)
Log("======================")

If Error.ToString="" Then
OK = True
Else
OK = False
End If
End If

Return OK

End Sub
</code>
 
Last edited:
Top