android how to check wifi is connected but no internet connection

mobile hotspot connected but no internet android
wifi connected no internet access
samsung hotspot connected but no internet
wifi connected but no internet windows 10
how to check wifi is connected but no internet access in android programmatically
my phone is connected to wifi but no internet iphone
wifi connected but no internet access windows 7
why does my phone say no internet connection when i have wifi

android my device connected with wifi but how to if wifi is connected but these is no internet connection

following is my code that i trying to check if no internet connection

public static boolean isConnectedWifi(Context context) {
        NetworkInfo info=null;
        if(context!=null){
            info= IsNetConnectionAvailable.getNetworkInfo(context);
        }
        return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI);
    }

it always return true when no internet access

NetworInfo.isAvailable and NetworkInfo.isConnected only indicate whether network connectivity is possible or existed, they can't indicate whether the connected situation has access to the public internet, long story short, they can't tell us the device is online indeed.

To check whether a device is online, try the following methods:

First:

@TargetApi(Build.VERSION_CODES.M)
public static boolean isNetworkOnline1(Context context) {
    boolean isOnline = false;
    try {
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkCapabilities capabilities = manager.getNetworkCapabilities(manager.getActiveNetwork());  // need ACCESS_NETWORK_STATE permission
        isOnline = capabilities != null && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return isOnline;
}

Strength: 1. could run on UI thread; 2. fast and accurate.

Weakness: need API >= 23 and compatibility issues.

Second:

public static boolean isNetworkOnline2() {
    boolean isOnline = false;
    try {
        Runtime runtime = Runtime.getRuntime();
        Process p = runtime.exec("ping -c 1 8.8.8.8");
        int waitFor = p.waitFor();
        isOnline = waitFor == 0;    // only when the waitFor value is zero, the network is online indeed

        // BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        // String str;
        // while ((str = br.readLine()) != null) {
        //     System.out.println(str);     // you can get the ping detail info from Process.getInputStream()
        // }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    return isOnline;
}

Strength: 1. could run on UI thread; 2. you can ping many times and do statistics for min/avg/max delayed time and packet loss rate.

Weakness: compatibility issues.

Third:

public static boolean isNetworkOnline3() {
    boolean isOnline = false;
    try {
        URL url = new URL("http://www.google.com"); // or your server address
        // URL url = new URL("http://www.baidu.com");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Connection", "close");
        conn.setConnectTimeout(3000);
        isOnline = conn.getResponseCode() == 200;
    } catch (IOException e) {
        e.printStackTrace();
    }

    return isOnline;
}

Strength: could use on all devices and APIs.

Weakness: time-consuming operation, can't run on UI thread.

Fourth:

public static boolean isNetworkOnline4() {
    boolean isOnline = false;
    try {
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress("8.8.8.8", 53), 3000);
        // socket.connect(new InetSocketAddress("114.114.114.114", 53), 3000);
        isOnline = true;
    } catch (IOException e) {
        e.printStackTrace();
    }

    return isOnline;
}

Strength: 1. could use on all devices and APIs; 2. relatively fast and accurate.

Weakness: time-consuming operation, can't run on UI thread.

SOLVED: WiFi Connected but No Internet Access, Fix Android Connected To WiFi But No Internet. Check If You Are Connected to the Internet. Check If Mobile Data is Turned Off. Disable and Enable WiFi on Android. Check Time and Date Settings. Forget and Reconnect to WiFi Network. Check If Router is Blocking Network Traffic. Change your DNS. Change Wireless Mode on [Solution] Android Connected To WiFi but No Internet Access. General Solution You Should Try Before Proceeding Further. Solution-1. On your phone under Settings>> WiFi >> Hold the Name of Your Network >> Now Click on Forgot Network.

The code you are using is just use to check if you are connected to wifi or not. It doesn't check if that wifi is slow or not. (No internet means slow connection).

I tried to use this code. Here, I try to hit google.com and have set a connection timeout value. If here internet speed is good, then result returned is 200. So I check if the result code is 200 or not. If not, I show an alert that there is slow internet connection. Use it in an asyntask, and onPostExecute() check the value of returned result.

HttpURLConnection urlc = null;
    try {
        urlc = (HttpURLConnection) (new URL("http://www.google.com")
                .openConnection());
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    urlc.setRequestProperty("User-Agent", "Test");
    urlc.setRequestProperty("Connection", "close");
    urlc.setConnectTimeout(1000); // choose your own timeframe
    urlc.setReadTimeout(2000); // choose your own timeframe
    try {
        urlc.connect();

        // returning connection code.
        return (urlc.getResponseCode());
    } catch (IOException e1) {
        e1.printStackTrace();
    }

Wi-Fi connected but there is no internet access, WiFi Connected But No Internet Access In Android/Samsung [FIXED] Check out our Duration: 3:34 Posted: Dec 7, 2018 1. Check if the Ethernet cable is properly connected to WAN port of your router. If the cable is not connected to Internet (WAN) port you will have working WiFi but no Internet access. Ensure your Ethernet cable is well-attached and the connector is not broken. Replace the patch cord is it is damaged.

After searching for days and after trying various solutions, some are not perfect some are too LONG, below is a solution suggested by LEVIT using SOCKETS which is PERFECT to me. Any one searching on this solution may consult this post. How to check internet access on Android? InetAddress never times out

Below is the portion of the code with example of task in AsyncTask

class InternetCheck extends AsyncTask<Void,Void,Boolean> {

    private Consumer mConsumer;
    public  interface Consumer { void accept(Boolean internet); }

    public  InternetCheck(Consumer consumer) { mConsumer = consumer; execute(); }

    @Override protected Boolean doInBackground(Void... voids) { try {
        Socket sock = new Socket();
        sock.connect(new InetSocketAddress("8.8.8.8", 53), 1500);
        sock.close();
        return true;
    } catch (IOException e) { return false; } }

    @Override protected void onPostExecute(Boolean internet) { mConsumer.accept(internet); }
}
///////////////////////////////////////////////////////////////////////////////////
// Usage

    new InternetCheck(internet -> { /* do something with boolean response */ });

Below is a summary related to the solution Possible Questions Is it really fast enough?

Yes, very fast ;-)

Is there no reliable way to check internet, other than testing something on the internet?

Not as far as I know, but let me know, and I will edit my answer.

What if the DNS is down?

Google DNS (e.g. 8.8.8.8) is the largest public DNS in the world. As of 2013 it served 130 billion requests a day. Let 's just say, your app would probably not be the talk of the day.

Which permissions are required?

<uses-permission android:name="android.permission.INTERNET" />

How come my phone says I'm connected to the wifi yet the internet , but no internet access in Android Device connects to WiFi hotspot but WiFi problem on Duration: 4:30 Posted: Nov 27, 2017 I don't want my user to even try downloading something unless they have Wi-Fi connected. However, I can only seem to be able to tell if Wi-Fi is enabled, but they could still have a 3G connection.

To just check if you are connected to the internet by Wi-Fi, have a look at the snippet below:

NetworkInfo getWifi(){
    ConnectivityManager connManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return mWifi;
}

Check whether it is connected or not by;

if(getWifi().isConnected()) {
//wi-fi connected
}

Fix Android Connected to WiFi But No Internet. Check If You Are Actually Connected to the Internet. I know, this sounds stupid. Check If Mobile Data is Turned Off. Disable and Enable WiFi on Android. Check Time and Date Settings. Forget and Reconnect to WiFi Network. Check If Router is Blocking Network Traffic. Change Open your Settings app "Wireless and Networks" or "Connections" tap Wi-Fi. Depending on your device, these options may be different. Turn Wi-Fi on. Find the Wi-Fi connection indicator at the top of

My father's Galaxy S Advance suddenly lost it's WiFi connectivity one day. I tried the code *#*#4636#*#* and tried to update the WiFi connection by disabling and​  Flush DNS. Sometimes, DNS cache conflict can lead to Wi-Fi connected but no internet access error. You can flush DNS to ensure it isn’t causing any trouble. Go to the Windows start menu and type ‘cmd’ to open Command Prompt and run it with admin rights. Type the following command and press enter to flush the DNS.

A strong Wi-Fi or mobile data connection will help you browse and download apps, It might sound simple, but sometimes that's all it takes to fix a bad connection. Turn Wi-Fi off and mobile data on, and check to see if there's a difference. or the host of the Wi-Fi network. Was this helpful? How can we improve it? Yes No. Whether you cannot connect at all or your Wi-Fi connection keeps dropping, toggling the Wi-Fi connection is known to be effective in many cases. Pull down the notifications area of your phone and look for the Wi-Fi icon, tap on it to switch it Off, wait for five seconds and turn it On again.

WiFi connected but no Internet is a common and annoying error, but the fix is not always straightforward. To identify router problems, connect other devices like your mobile phone to the WiFi and see if it works. For this, check if the “Internet” light on the modem is working. Saitheja @ Android Tips.

Comments
  • Hey, did you solve this issue?
  • You may be find an answer from here: stackoverflow.com/q/6493517/6482350
  • it took me the lot of time to check internet connection
  • is there any other way to check
  • you may try with this: stackoverflow.com/questions/2802472/…
  • I also had the same problem, I am following the same code I gave, and it helps me in finding slow internet connection. There is no method to check if the wifi connection we are connected to is able to ping or not. :)
  • If this answer has some technical flaw, please elaborate before voting down because for me, this is working fine and I posted it here so that other people searching on same issue can find the answer here or on given link. Thanks.
  • Kaveesh Kanwal, this is not what he asked for. Code snippet you gave is just to check if the device is connected to wifi or not. It doesn't test internet speed.
  • The OP has not asked how to check internet speed. Good luck.
  • He has also not asked how to check if device is connected to wifi. :) By no internet access, all we can do is just check packet sending speed on that nw.
  • i tried these but i have to check wifi connection and internet connection both
  • but the above code return me the only wifi is connected or not