Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, how to override the internet connectivity check when connecting to wifi network?

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?

like image 899
ashishduh Avatar asked Jul 24 '16 18:07

ashishduh


People also ask

How can I remove data connectivity problem?

Restart your device. Open your Settings app and tap Network & internet or Connections. Depending on your device, these options may be different. Turn Wi-Fi off and mobile data on, and check if there's a difference. If not, turn mobile data off and Wi-Fi on and check again.

Why is my Android phone connected to Wi-Fi but no internet?

A common reason why your phone has a WiFi connection but no Internet access is that there is a technical issue with your router. If your router is experiencing any kind of bugs or problems, that affects how your devices including your Android devices connect to the Internet.


2 Answers

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.

like image 56
sssemil Avatar answered Sep 27 '22 19:09

sssemil


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;
}
like image 45
Dipali Shah Avatar answered Sep 27 '22 17:09

Dipali Shah