Android Question Check correct internet connection

Discussion in 'Android Questions' started by omidaghakhani1368, Jul 7, 2015.

  1. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed 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?
     
    ArminKH likes this.
  2. lemonisdead

    lemonisdead Well-Known Member Licensed User

    Hello,
    HotShoe's MLWifi has a method to detect if you are connected (WiFi or mobile)
     
  3. ArminKH

    ArminKH Well-Known Member

    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
     
    omidaghakhani1368 likes this.
  4. corwin42

    corwin42 Expert Licensed User

    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:
    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
     
  5. ArminKH

    ArminKH Well-Known Member

    is this works when wifi is on but there is not any connection?
     
  6. corwin42

    corwin42 Expert Licensed User

    Yes. It just checks if the device has any internet connection.
     
    ArminKH likes this.
  7. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Thank you but if connect to network thus i have a valid ip example 192.168.1.1 and it is wrong
     
    ArminKH likes this.
  8. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Thank you.i try it
     
  9. ArminKH

    ArminKH Well-Known Member

    i'am not sure that i understand what you mean,ok follow corwin's way
     
Loading...