11

I've noticed on Marshmallow (e.g. Nexus 6P) and also on some more recently updated Lollipop phones (e.g. Galaxy S5) that when I connect to a wifi network that has no internet, the network will not fully connect until the user accepts the prompt stating that the network has no internet access.

Is there any way to programmatically get around this check and allow wifi connections to proceed regardless of internet access?

ashishduh
  • 6,254
  • 3
  • 27
  • 35
  • Android itself has not exposed any method which does this. You can do this by reflection for each vendor. Seems like only solution and not a good one. – ozmank Sep 06 '16 at 13:57

3 Answers3

1

Didn't try these but you might try redirecting www.google.com and 8.8.8.8 to 127.0.0.1 (you can use iptables or modify /system/hosts). You can also try digging AOSP source code (these are the only isReachable() checks I found in AOSP).

If you decide to lookup AOSP, you can start here

P.S. You'll need root for iptables and /system/hosts manipulation.

Sanoop Surendran
  • 3,241
  • 3
  • 24
  • 46
sssemil
  • 240
  • 5
  • 12
1

You may try this

To verify network availability:

private Boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager 
          = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}

To verify internet access(connected wifi is active or not):

public Boolean isOnline() {
    try {
        Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com");
        int returnVal = p1.waitFor();
        boolean reachable = (returnVal==0);
        return reachable;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}
Dipali Shah
  • 3,355
  • 28
  • 46
0

Check these Link..

check Internet connection

public final boolean isInternetOn()
{
  ConnectivityManager connec = (ConnectivityManager)
    getSystemService(Context.CONNECTIVITY_SERVICE);

  // ARE WE CONNECTED TO THE NET
  if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
       connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED )
  {
    // MESSAGE TO SCREEN FOR TESTING (IF REQ)
    //Toast.makeText(this, connectionType + ” connected”, Toast.LENGTH_SHORT).show();
    return true;
  }
  else if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED
    ||  connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED  )
  {
    return false;
  }

  return false;
  }

check Internet connection with url if available

public static boolean hasActiveInternetConnection(Context context) {
    if (isNetworkAvailable(context)) {
        try {
            HttpURLConnection urlc = (HttpURLConnection) (new URL("http://www.google.com").openConnection());
            urlc.setRequestProperty("User-Agent", "Test");
            urlc.setRequestProperty("Connection", "close");
            urlc.setConnectTimeout(1500); 
            urlc.connect();
            return (urlc.getResponseCode() == 200);
        } catch (IOException e) {
            Log.e(LOG_TAG, "Error checking internet connection", e);
        }
    } else {
        Log.d(LOG_TAG, "No network available!");
    }
    return false;
}
Community
  • 1
  • 1
Arjun saini
  • 3,891
  • 2
  • 16
  • 44