Below I am displaying the current state of the ´WiFi´ network using a textview
, but if the current state of the network changes, for example while the App is running and the user turned the WiFi
off, the textview
would change accordingly. what i am trying to do is, to have a textview
that can display the current status of the WiFi
network accordingy.
How to achieve this. I hope my question is clear.
Code:
private boolean IsWiFiConnected() {
// TODO Auto-generated method stub
ConnectivityManager mconnMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNWInfo = mconnMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mNWInfo != null) {
if (mNWInfo.isConnected()) {
setText(R.id.tv_conn_status, "WiFi is now connected: "+mNWInfo.isConnected());
return true;
}else if (mNWInfo.isConnectedOrConnecting()) {
setText(R.id.tv_conn_status, "WiFi is now connecting/connected: "+mNWInfo.isConnectedOrConnecting());
return true;
}else if (mNWInfo.isAvailable()) {
setText(R.id.tv_conn_status, "WiFi is now available: "+mNWInfo.isAvailable());
return false;
}else if (mNWInfo.isFailover()) {
setText(R.id.tv_conn_status, "WiFi is now in faiover: "+mNWInfo.isFailover());
return false;
}else if (mNWInfo.isRoaming()) {
setText(R.id.tv_conn_status, "WiFi is now available: "+mNWInfo.isRoaming());
return false;
}
}
return false;
}