Home » Mobile » Android » Android Check internet connectivity

Android Check internet connectivity

Android Check internet connectivity.

Below android code to check if mobile is connected to internet or not ?

public static boolean isConnectingToInternet(Context context) {
try {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
} catch (Exception e) {
CustomLogHandler.printInfolog(“Exception”, ” e “+e.getMessage());
}
return false;
}

About

Software Developer in android,java,phone gap,angular js etc interested in challenging work in problem solving.

Leave a Reply