I am trying to check Internet connectivity on Android using the following method. I have a Wi-Fi connection.
private boolean checkInternetConnection() {
Simply drag and open the control center and click on the airplane mode button as what you are doing on your actual device.
Please bear with me for a very slow emulator.
To check on a real device (and also in the emulator), go to:
Settings > Wireless and Networks > Mobile Networks > Data enabled
Uncheck it and it will work.
Recent emulator versions provide an easier way, from an ADT view:
Window -> Show view -> Other... -> Android -> Emulator Control
Simply change "Data" value from "Telephony Status" and test your application again.
You can disable the Internet connection by pressing F8 in any Android emulator. It is a toggle button, so if it doesn't have Internet connection then it will start the Internet connection and if it already has an Internet connection then it will dis-connect it.
You can actually disable internet connection in the simulator just as you would in a real phone.
I just tried it successfully in an android 4.4 image loaded into my simulator.
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo().isConnectedOrConnecting();
}