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

Algorithm for Airplane Seat Reservation System

Open Gallery and get the selected image in appplication

Open Contacts using Intent and get Contact in onActivityResult()