dear friends,
i want to check internet connectivity in each activity if lost then it should display a message.
can any one guide me how to achieve this?
any help would be appriciated.
dear friends,
i want to check internet connectivity in each activity if lost then it should display a message.
can any one guide me how to achieve this?
any help would be appriciated.
You can use the ConnectivityManager to check the network state.
ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
if ( conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED
|| conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ) {
//notify user you are online
}
else if ( conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED
|| conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED) {
//notify user you are not online
}