Checking Network Connection In Android

For checking connection status in Android, first we need to get an instance of ConnectionManager using getSystemService(). The syntax is as,

ConnectionManager connManager = (ConnectionManager)getSystemService(Context. CONNECTIVITY_SERVICE);

if ( connManager .getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED || connManager .getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ) {
text.setText("hey your online!!!");
//Do something in here when we are connected
} else if ( connManager.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED || connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED ) {
text.setText("Look your not online");


Popular posts from this blog

AlarmManager and Notification in Android

Swipe Action and ViewFlipper in Android