Android Question Check correct internet connection

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Hi.
I found some code for check internet connection in forum
But you consume i connect to wireless but internet is disable or not connected
In this state,again return true
it is wrong because i cannot send data
how can i detect internet state correctly?
 
Hi.
I found some code for check internet connection in forum
But you consume i connect to wireless but internet is disable or not connected
In this state,again return true
it is wrong because i cannot send data
how can i detect internet state correctly?
also i think you can check whether your device has ip address or not
because each device which is connected to internet has a ip addrees
 
Upvote 0
I currently use the "official" Google recommended way to check an internet connection as explained here: http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html

The B4A implementation using Reflection library is here:
Code: Copy
Sub CheckConnection As Boolean
    Dim r As Reflector
   
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
    r.Target = r.RunMethod("getActiveNetworkInfo")
   
    If r.Target <> Null Then
        Return r.RunMethod("isConnectedOrConnecting")
    End If
   
    Return False
End Sub
 
Upvote 0
I currently use the "official" Google recommended way to check an internet connection as explained here: http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html

The B4A implementation using Reflection library is here:
Code: Copy
Sub CheckConnection As Boolean
    Dim r As Reflector
  
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
    r.Target = r.RunMethod("getActiveNetworkInfo")
  
    If r.Target <> Null Then
        Return r.RunMethod("isConnectedOrConnecting")
    End If
  
    Return False
End Sub
is this works when wifi is on but there is not any connection?
 
Upvote 0
is this works when wifi is on but there is not any connection?
Yes. It just checks if the device has any internet connection.
 
Upvote 0
also i think you can check whether your device has ip address or not
because each device which is connected to internet has a ip addrees
Thank you but if connect to network thus i have a valid ip example 192.168.1.1 and it is wrong
 
Upvote 0
I currently use the "official" Google recommended way to check an internet connection as explained here: http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html

The B4A implementation using Reflection library is here:
Code: Copy
Sub CheckConnection As Boolean
    Dim r As Reflector
  
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
    r.Target = r.RunMethod("getActiveNetworkInfo")
  
    If r.Target <> Null Then
        Return r.RunMethod("isConnectedOrConnecting")
    End If
  
    Return False
End Sub
Thank you.i try it
 
Upvote 0
Back
Top