简体   繁体   中英

Get Internet state change while wifi is connected

I want to know if there is any intent or broadcast that notifies when internet is connected/disconnected while the wifi/data network is connected all the time. I am aware of CONNECTIVITY_CHANGE but it only notifies when wifi/data is switched on/off.

Thanks

In my case this block of code is working fine, you must try it

public boolean isInternetAvailable() {
try {
    InetAddress ipAddress = InetAddress.getByName("google.com"); 
    //You can replace it with your name
        return !ipAddress.equals("");

    } catch (Exception e) {
        return false;
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM